Jump to content

order


stretch25

Recommended Posts

<?

$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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.