PHP MySQL ORDER BY Keyword

The ORDER BY keyword is uing to sort the data in a recordset.[ascending order by default.]

If you want to sort the records in a descending order  then you can use the DESC keyword.

SELECT column_name(s) FROM table_name ORDER BY column_name(s) ASC|DESC

ORDER BY
<?php

$con=mysqli_connect(“example.com”,”user01″,”password”,”my_db”);
// Check connection
if (mysqli_connect_errno())
{
echo “Failed to connect to MySQL: ” . mysqli_connect_error();
}

$result = mysqli_query($con,”SELECT * FROM users ORDER BY age”);

while($row = mysqli_fetch_array($result))
{
echo $row[‘FirstName’];
echo ” ” . $row[‘LastName’];
echo ” ” . $row[‘Age’];
echo “
“;
}

mysqli_close($con);

?>