PHP – MySQL – Order By Keyword

Statement:

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

<?php
// Create connection
// Statement: mysqli_connect(host,username,password,dbname)
// NOTICE: se lo script è installato nello stesso server del Data Base, host->localhost
$con=mysqli_connect("localhost","lucedigi_user","mypassword","lucedigi_testphp");

// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

// Order records START
$result = mysqli_query($con,"SELECT * FROM Persons ORDER BY age");

while($row = mysqli_fetch_array($result))
  {
  echo $row['FirstName'];
  echo " " . $row['LastName'];
  echo " " . $row['Age'];
  echo "<br>";
  }
// Order records END

mysqli_close($con); 
echo "Great! Connection Closed!"; 
?>

phpMyAdmin:

mysql-0004

The result:

Glenn Quagmire 33
Peter Griffin 35
Andrea Tonin 39