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 Link to comment https://forums.phpfreaks.com/topic/209386-ordering-data-correctly/ 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"; Link to comment https://forums.phpfreaks.com/topic/209386-ordering-data-correctly/#findComment-1093318 Share on other sites More sharing options...
Freid001 Posted July 30, 2010 Author Share Posted July 30, 2010 Thanks that works fine !!! :D Link to comment https://forums.phpfreaks.com/topic/209386-ordering-data-correctly/#findComment-1093348 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.