the links you mentioned should target the same page, construct them like this:
<a href="<?=$SERVER['PHP_SELF']"; ?>?orderby=date">
(you don't have to use the $SERVER variable but can write the script name directly. but if you rename the script later you'd be required to adapt each of the links.)
now when the user clicks the link your script starts anew and you should catch the orderby value (beginning part of the script):
if($_GET['orderby'])
{
// ... here comes the "restriction" code
}
the restriction code can be a if-else or a switch construction. the goal is to create a sql snippet: the order by clause.
$sql_order_by = ''; // fore safety reasons, initialize.
OR:
$sql_order_by = ' order by creationdate desc'; // predefined default value
if($GET['orderby'])
{
if($GET['orderby'] == 'date')
$sql_order_by = ' order by date';
elseif($_GET['orderby'] = 'user')
$sql_order_by = ' order by lastname,firstname';
}
// now append that part to your select statement, done!
$sql = 'select ... from ...'.$sql_order_by;
// -> query -> table output
warning: be sure NOT to include the value in $_GET['orderby'] directly into your sql statement!! manipulations could occur (sql injection)!
UNSAVE, BEWARE, NO-NO!:
$sql = 'select ... order by '.$_GET['orderby'];