I would change your query into a variable then make the headings links.
something like:
<?php
mysql_select_db("db", $con);
if (isset($_GET['direction']) && $_GET['direction'] == "DESC"){
$direction = "DESC";
$opposite = "ASC";
} else {
$direction = "ASC";
$opposite = "DESC";
}
if (isset($_GET['orderby'])){
$orderby = $_GET['orderby'];
} else {
$orderby = "first_name";
}
$query = "SELECT * FROM staff ORDER BY {$orderby} {$direction}";
$result = mysql_query($query) or die ("Database Read Error: " . mysql_error());
echo "<table border='1'>
<tr>
<th><a href=\"page.php?orderby=first_name&direction={$opposite}\">First Name</a></th>
<th><a href=\"same except last_name\">Last Name</a></th>
<th><a href=\"age\">Age<a/></th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['firstName'] . "</td>";
echo "<td>" . $row['lastName'] . "</td>";
echo "<td>" . $row['age'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
There is probably something more elegant, but that is what I have done in the past and been successful. You probably wouldn't want to use the code exactly as I wrote 1)Because I didn't write out all the proper urls and 2)terrible mysql security. But hopefully this will help steer you in the direction you wanted.