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
https://forums.phpfreaks.com/topic/92115-order-by-problem/
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
https://forums.phpfreaks.com/topic/92115-order-by-problem/#findComment-471738
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
https://forums.phpfreaks.com/topic/92115-order-by-problem/#findComment-471759
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.