Add a bit of querystring to the colum head links; linking back to the same URL, and with "?sortby=name&sortdir=asc" or "?sortby=id&sortdir=desc" or whatever is appropriate ("sortdir" is given so that if they're already sorted in ascending order, clicking it again lists them in descending order, and vice versa).
Then in the script retrieving the stuff from the database:
$sort='';
switch($_GET['sortby'])
{
case 'id': $sort .= "id"; break;
case 'name': $sort .= "name"; break;
case 'manufacturer': $sort .= "manufacturer"; break;
default: break;
}
// Where the value appended to $sort
// is the name of the relevant field
if($_GET['sortdir']=='desc')
$sort.=' DESC';
elseif($_GET['sortdir']=='asc')
$sort.=' ASC';
Build your $query up to where the ORDER BY clause would go (if there is a LIMIT clause, leave it off for now), and then go
if($sort!='')
$query.= ' ORDER BY '.$sort;
And then tack on the LIMIT clause if there is one.
'Course, I've seen this done entirely client-side in Javascript; but too many people are still faffing around with noncompliant browsers...