How do I order MySQL data?:
When you query your MySQL database, you can sort the results by any field in an ascending or descending order by just adding 'ORDER BY' at the end of your query. You would use ORDER BY field_name ASC for an ascending sort, or ORDER BY field_name DESC for a descending sort.
In the code above we are retrieving data from an address book, and we are sorting by the person's name in an ascending fashion.
$data = mysql_query("SELECT * FROM address ORDER BY name ASC")
Here we are selecting only the email addresses, and listing them in a descending order.
$data = mysql_query("SELECT email FROM address ORDER BY email DESC")