I have a webpage that has a table with 3 columns.
I have the first row of the table holding the column names, which are clickable and do sort the list in ascending order.
I need to have it so that if you click on a header once, it sorts the display asceding. And if you click it again, it sorts it descending.
Here is the code that I have working so far:
<?php
// If the $orderby variable is not set, default to 'TeaType'
if (! isset($orderby)) :
$orderby = "TeaType";
endif;
// create and execute query. Any retrieved data is sorted in ascending order
$query = "SELECT ID, TeaType, Flavour, Company, CompanyURL FROM teas ORDER BY $orderby";
$result = mysql_query($query);
// create table header
?>
<table border = 1 >
<tr>
<th><a href="teajournalindex.php?orderby=TeaType" title="Click to sort in ascending order by Tea Type">Tea Type</a></th>
<th><a href="teajournalindex.php?orderby=Flavour" title="Click to sort in ascending order by Flavour">Flavour</a></th>
<th><a href="teajournalindex.php?orderby=Company" title="Click to sort in ascending order by Company">Company</a></th>
</tr>
In the title portion of the 3 href links, I need to replace ascending with a variable that holds whether clicking will sort ascending, or descending. I hope that makes sense.
And here is the page that I have up.
http://www.solitaryspaces.com/teajournal/teajournal.php
Thanks in advance.