Listing items...
How would I list a series of items in order from greatest to least? For example:
Item A - 462
Item B - 903
Item C - 824
The script would print those items like this:
1. Item B
2. Item C
3. Item A
Also, how could I make a list of items according to the date, starting with the newest and ending with the oldest?
Thanks!!
--Edge
sordid posted this at 05:01 — 3rd October 2000.
They have: 13 posts
Joined: May 1999
You could do that by first sorting the array.
Get the last value of the array by using $i = $#array.
Next use a loop to print out each item starting with the last, decrementing $i each time you do it. Oh hell, like this, haha :
@array = ("223", "479", "145", "906", 400");
@array = sort(@array);
$i = $#array; #gets the last item number in the array
$z = 0; #first item in the array
while ($i >= $z) {
print "$array[$i]\n";
$i--;
}
finit
should do the trick for ya.
sordid posted this at 05:04 — 3rd October 2000.
They have: 13 posts
Joined: May 1999
As for the date thing, try using numbers for your dates :
"yymmdd" format will organize your dates by newest to oldest.
Cheers!
Rob Pengelly posted this at 11:47 — 3rd October 2000.
They have: 850 posts
Joined: Jul 1999
@array = ("462","903","824");
print(reverse(sort @array));
outputs
903824462
As for the date, you could use the localtime() feature, which outputs the date in a 9-number variable. Then you could just sort() the array of dates to display least to greatest.
http://www.thehungersite.com - http://www.therainforestsite.com
http://www.ratemymullet.com - Beauty is only mullet deep.
sordid posted this at 02:18 — 4th October 2000.
They have: 13 posts
Joined: May 1999
Cool
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.