Add this to the end of your MySQL query "(REST OF OLD QUERY HERE) ORDER BY order " . $sort;
You will need to make links labeled up/down (or something similiar probably) that pass an argument to your script in which way to sort your results.
E.g.: <a href="index.php?sort=>Ascending</a> <a href="index.php?sort=desc>Descending</a>
Then, in your PHP script, before the query:
$sort = ''; // Default order ascending (auto)
if ( isset ( $_GET [ 'sort' ] ) )
{
if ( $_GET [ 'sort' ] == 'desc' )
{
$sort = 'DESC';
}
}
Explanation:
MySQL orders your results ascending by default, so we have to add nothing to the query normally ($sort='';
). However, if the user clicks the Descending link, PHP sets $sort
to DESC
and MySQL will order your results descending!