ciao se ho capito bene io farei così:
Codice PHP:
if (empty($_GET['order_by'])) $_GET['order_by'] = 'userid';//ordine di visualizza di default
 
$order_by $_GET['order_by'];

if (empty(
$_GET['sort_order'])) {
  
$_GET['sort_order'] = 'ASC';
  
$sort_order 'ASC';
}

if (
$_GET['sort_order'] == 'ASC')  {
  
$sort_order 'DESC';
  
$org_sort_order 'ASC';
}
  else {
    
$sort_order =  'ASC';
    
$org_sort_order 'DESC';








   
$query "SELECT userid, data FROM $user_tablename ORDER BY 
                                  
$_GET[order_by] $_GET[sort_order]";
   
   
$result mysql_query($query);   
   if(!
$resulterror_message(sql_error());
?> 
nei nomi dei campi sche scrivi nella tabella inserisci i collegamenti x ordinare i campi
TABLE BORDER="1" WIDTH="90%" CELLPADDING="2">
<TR>
<TH WIDTH="25%" NOWRAP>
<A HREF="<?php echo "$PHP_SELF?action=list_records&sort_order=$sort_or der&order_by=userid"; ?>">
Userid
</A>
</TH>
<TH WIDTH="25%" NOWRAP>
<A HREF="<?php echo "$PHP_SELF?action=list_records&sort_order=$sort_or der&order_by=titolo"; ?>">
Data
</A>
</TH>
<TH WIDTH="25%" NOWRAP>Azioni</TH>
</TR>