So I want to order values in my database from highest to lowest. The only thing it does now is randomly scramble up all results, meaning it just puts 100 below 50 in the middle and 1 in the top.
<?php
$con=mysqli_connect("localhost","username","password","table");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM playerdata ORDER BY Gold");
while($row = mysqli_fetch_array($result)) {
echo $row['Username'];
echo " " . $row['Gold'];
$row['Unique_ID'];
echo "<br>";
}
mysqli_close($con);
?>
SELECT * FROM playerdata ORDER BY Gold DESC
Mysql does not order by value but Mysql does order by value based on the type . If we take an example : you have a table TABLE1
that contain two columns C1
and C2
where C1
is INT
and C2
is VARCHAR
and we have a set of :
C1 C2
1 1
2 2
10 10
so
SELECT * from TABLE1 ORDER BY C1 DESC
shows
C1 C2
10 10
2 2
1 1
but
SELECT * from TABLE1 ORDER BY C2 DESC
will shows
C1 C2
2 2
10 10
1 1
so pay attention to your schema and your data .