Freid001 Posted July 30, 2010 Share Posted July 30, 2010 Hi i am trying to order data however i get a problem. The problem is that it orders the data but only by the first number! Example: (Place 1) Freid001: 981 (Place 2) mark: 90000 (Place 3) Tom: 5 (Place 4) Ash 1000 Here is the code i am using: $query = "SELECT * FROM Game ORDER BY XP"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); echo "<table border='0'>"; echo "<tr> <th>User</th> <th>XP</th> </tr>"; while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "</td><td>"; echo $row['User'] ; echo "</td><td>"; echo $row['XP']; } echo "</table>"; ?> Thanks Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted July 30, 2010 Share Posted July 30, 2010 That's the default ORDER from MySQL; it tries to sort the numbers pseudo-alphabetically. Try this instead, and see what you get $query = "SELECT `User`, `XP` FROM `Game` ORDER BY CAST(`XP` AS SIGNED INTEGER) DESC"; Quote Link to comment Share on other sites More sharing options...
Freid001 Posted July 30, 2010 Author Share Posted July 30, 2010 Thanks that works fine !!! :D 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.