timmah1 Posted June 24, 2008 Share Posted June 24, 2008 I'm selecting a person's worth from the database, I need to list them from highest to lowest. These are the numbers in the database as of right now 20609 5480 9587 My code is this $result = mysql_query("SELECT * FROM profile ORDER BY worth ASC"); $i = 1; Then to display them while($row = mysql_fetch_array($result)) { $number = $row['worth']; $format_number = number_format($number, 2, '.', ','); echo $i; $format_number; ++$i; } The problem I'm having is that it lists the numbers like they are above, not in order from highest to lowest 20609 5480 9587 If I change it to DESC, it displays like this 9587 5480 20609 Can anybody see what the problem is? Thanks in advance Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 24, 2008 Share Posted June 24, 2008 It looks as if the field type for worth is a text field and not a numeric field. If you order those values as if they were text then the results you are getting is correct: a 2 comes before a 5 just as B comes before F. Change the field type of "worth" to an appropriate numeric field. EDIT: You also have several unnecessary lines. No reason to create the variable $number just to use it one on the next line: <?php $query = "SELECT * FROM profile ORDER BY worth ASC"; $result = mysql_query($query) or die (mysql_error()."<br>$query"); $i = 1; while($row = mysql_fetch_array($result)) { echo $i++ . number_format($row['worth'], 2, '.', ','); } ?> And whay are you not following the advice you are including in your own sig? Quote Link to comment Share on other sites More sharing options...
timmah1 Posted June 24, 2008 Author Share Posted June 24, 2008 oh geez, simple stuff. works perfect now, thank you mjdamato Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.