Jump to content

Ordering Data Correctly


Freid001

Recommended Posts

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  :D

Link to comment
https://forums.phpfreaks.com/topic/209386-ordering-data-correctly/
Share on other sites

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";

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.