Hello,
What you are trying to do is simple really. First of all, you will be creating a dynamic SQL query, that will change depending on which header link the user clicks. Each header link is a simple HREF that links to itself (i.e. $PHP_SELF).
Before you get to the SQL code, set up a switch control which will determine the kind of ordering the user wants.
switch ($order) {
//here you change the value of $order
//so that it matches your tables
//field names
case "given":
$order = "given_name";
break;
case "title":
$order = "title";
break;
default:
//there is no check for surname
//above because it is handled
//here as the default
//this takes care of two
//problems at once
//this will order your table
//on surname by default
$order = "surname";
break;
} //endswitch
Your SQL code should look similar to:
SELECT
given_name,
surname,
title
FROM
employees
ORDER BY
$order
The HREF links of your headers would simply read (quote escaping depends on if you are inside a PHP block or not - here the quotes are escaped):
<a href=\"$PHP_SELF?order=given\">Given Name</a>
Alternately you could populate your querystring values directly from the field names of your tables, but I think a slow start is what you are looking for right now.
Hope it helps...