Jump to content

ORDER BY, Problem.


smithmr8

Recommended Posts

Hi,

I am using the below code, to display people with the most money on hand and in the bank by order of the amount in descending order, but its not quite working properly.

 

2d8hv82.jpg

 

<?php
$mostmoney = mysql_query("SELECT * FROM `users` ORDER BY `money` DESC LIMIT 10");
$mostbank = mysql_query("SELECT * FROM `users` ORDER BY `bank` DESC LIMIT 10");
echo "<table cellpadding=0 cellspacing=0 width=476 height=227>";
echo "	<tr>";
echo "	<td valign=top width=230>";
echo "<b>Most Money (In Hand)</b><br>";
  while ($money = mysql_fetch_array($mostmoney)) {
  echo "#. ".$money['username']." (£".$money['money'].")<br>";
  }
  echo "</td>";
echo "	<td width=16> </td>";
echo "	<td valign=top height=227 width=230>";	
  echo "<b>Most Money (Bank)</b><br>";
  while ($bank = mysql_fetch_array($mostbank)) {
  echo "#. ".$bank['username']." (£".$bank['bank'].")<br>";
  }
  echo "</td>";
echo "</tr>";
echo "</table>";
?>

 

Thanks :D

Link to comment
Share on other sites

Make sure your money field type is INT but be honest I don't see any reason why it shouldn't work. Try cleaning up your html a little

<?php
$mostmoney = mysql_query("SELECT * FROM `users` ORDER BY `money` DESC LIMIT 10");
$mostbank = mysql_query("SELECT * FROM `users` ORDER BY `bank` DESC LIMIT 10");
echo "<table cellpadding=\"0\" cellspacing=\"0\" width=\"476\" height=\"227\">";
echo "	<tr>";
echo "	<td valign=\"top\" width=\"230\">";
echo "<strong>Most Money (In Hand)</strong><br />";
 while ($cash = mysql_fetch_array($mostmoney)) {
   echo "#. {$cash['username']} (£{$cash['money']})<br />";
 }
 echo "</td>";
 echo "	<td width=\"16\"> </td>";
 echo "	<td valign=\"top\" height=\"227\" width=\"230\">";	
 echo "<strong>Most Money (Bank)</strong><br />";
 while ($account = mysql_fetch_array($mostbank)) {
   echo "#. {$bank['username']} (£{$bank['bank']})<br />";
 }
 echo "</td>";
echo "</tr>";
echo "</table>";
?>

Link to comment
Share on other sites

The way money is configured, everything is in whole numbers. £1, £1954, £19405 ect.. :P

 

Also,

for ($num=1; $num <= 10; $num++ ){
  while ($money = mysql_fetch_array($mostmoney)) {
    echo $num.". ".$money['username']." (£".$money['money'].")<br>";
}
}

 

Im trying to get it to list them and replace the '#' shown above with the corresponding number. This code is making them all '1'. Any ideas ?

 

Thanks

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.