stretch25 Posted October 4, 2008 Share Posted October 4, 2008 <? $b1 = mysql_query("SELECT * FROM crews WHERE owner!='Stretch'"); while($f1 = mysql_fetch_object($b1)){ $test = mysql_query("SELECT * FROM users WHERE userlevel='0' AND location='$f1->location' AND status='Alive'"); $test2=mysql_num_rows($test); $ttest='0'; while($test3 = mysql_fetch_object($test)){ $test6 = mysql_fetch_object(mysql_query("SELECT * FROM bank_account WHERE location='$f1->location' And username='$test3->username'")); $ttest=$ttest+$test3->money+$test6->money; } $ttest=$ttest+$f1->bank; echo " <tr> <td>$f1->location</td> <td>$f1->owner</td> <td>$test2</td> <td>$".number_format($ttest)."</td> </tr>"; } ?> i would like to order the echo from highest to lowest from $ttest but im really not sure how to with using 2 whiles other then making a new table in the db but there has to be a easyer way. thanks Link to comment https://forums.phpfreaks.com/topic/126968-order/ Share on other sites More sharing options...
btherl Posted October 4, 2008 Share Posted October 4, 2008 Have you used arrays before? It can also be done purely in SQL using group by, I think. The strange variable names you've used have confused me though, so I'm not entirely sure what you are adding up. Link to comment https://forums.phpfreaks.com/topic/126968-order/#findComment-656944 Share on other sites More sharing options...
stretch25 Posted October 4, 2008 Author Share Posted October 4, 2008 this is what it echos Richest Province Proviince Owner People Worth Ontario Stone 13 $430,090,882 Newfoundland Oldskool 51 $113,658,781 New Brunswick Murphy 11 $1,776,469,408 Quebec wadah 8 $1,026,426,745 Nova Scotia TapOut 9 $1,036,976,690 Prince Edward Island jews 9 $30,772,634 im trying to order worth from highest to lowest Link to comment https://forums.phpfreaks.com/topic/126968-order/#findComment-656987 Share on other sites More sharing options...
Barand Posted October 4, 2008 Share Posted October 4, 2008 Easiest way, without rewriting the queries, is to store the data in an array instead of echoing it. Then sort the array and output the data. replace echo " <tr> <td>$f1->location</td> <td>$f1->owner</td> <td>$test2</td> <td>$".number_format($ttest)."</td> </tr>"; with $data[] = array ($f1->location, $f1->owner, $test2, $ttest); then function mysort($a, $b) { return $b[3] - $a[3]; } usort($data, 'mysort'); foreach ($data as $item) { echo "<tr> <td>$item[0]</td> <td>$item[1]</td> <td>$item[2]</td> <td>\$".number_format($item[3])."</td> </tr>"; } Link to comment https://forums.phpfreaks.com/topic/126968-order/#findComment-657009 Share on other sites More sharing options...
stretch25 Posted October 4, 2008 Author Share Posted October 4, 2008 thanks alot worked out great Link to comment https://forums.phpfreaks.com/topic/126968-order/#findComment-657127 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.