Jasp182 wrote:Have two variables - one to store what the current sort field is and another to store whether the sort is ASC or DESC. If the field is not what is currently being sorted by, link to file.php?order=id;sort=<default sort for this column>. If the field is currently being sorted, link to file.php?order=id;sort=<opposite of sort variable>.
Actually, the GET variables are separated by ampersands (&) not semicolons. But close enough 😃
Yes, Jasp is correct - make two button images, an up arrow and a down arrow, and make them the links I suggested earlier. Make the up one link to "file.php?order={rowname}&sort=asc" and the down one "file.php?order={rowname}&sort=desc". Then just include this in your SQL query:
SELECT * FROM table ORDER BY $order {$_GET['sort']}
Or for you security-conscious folks, a quick if statement beforehand:
if ($_GET['sort'] == "asc")
$sort = "asc";
else
$sort = "desc";
and replace "$_GET['sort']" in the SQL query with "$sort".