This is an example out of a book I am working through right now, however, it only allows you to sort by ASC if you click the link once, so if you click username it sorts it by ASC, but I was wondering if it is possible to set it up so that if you clicked the same link again it went to DESC, that way you could switch views while still only using one link?
Thanks for any help that can be provided.
//Default sort order by registration date
$sort = (isset($_GET['sort'])) ? $_GET['sort'] : 'rd';
//Determine how the results should be ordered
switch($sort)
{
case 'ln':
$order_by = 'last_name ASC';
break;
case 'fn':
$order_by = 'first_name ASC';
break;
case 'rd':
$order_by = 'registration_date ASC';
break;
case 'un':
$order_by = 'username ASC';
break;
default:
$order_by = 'registration_date ASC';
$sort = 'rd';
break;
}
//Build the table
echo '<table cellspacing="0" cellpadding="5" width="100%">
<tr>
<td align="left"><strong><a href="view_users.php?sort=un">Username</a></strong></td>
<td align="left"><strong><a href="view_users.php?sort=fn">First Name</a></strong></td>
<td align="left"><strong><a href="view_users.php?sort=ln">Last Name</a></strong></td>
<td align="left"><strong><a href="view_users.php?sort=rd">Date Registered</a></strong></td>
<td align="left"><strong>Edit</strong></td>
<td align="left"><strong>Delete</strong></td>
</tr>';