Page 1 of 1

column sort

Posted: Mon Sep 29, 2003 11:29 am
by sulen
I have a table on a page with 5 columns obtaining data to fill them from a Mysql DB. I want to make the column headers links which when clicked sorts the contents of the column in asc or desc order.

This is the code for my table

<table width='100%'>
<tr>
<td>Site ></td>
<td>Site Status</td>
<td>Company Name</td>
<td>City</td>
<td>State</td>
<td>Group Code</td>
</tr>
<?
for($i=0; $i <$num_results1; $i++)
{
$row = mysql_fetch_array($result2);
$siteno=$row[22];
$cname=$row[1];
$sstatus=$row[0];
$scity=$row[4];
$cstate=$row[5];
$gcode=$row[8];
?>
<tr>
<td><a class="five" href="sdetail.php?siteno=<?=$siteno?>&cname=<?=$cname?>&sstatus=<?=$sstatus?>&scity=<?=$scity?>&cstate=<?=$cstate?>&gcode=<?=$gcode?>"><font color='#EFA61F'><?=$siteno?></font></div></td>
<td><?=$sstatus?></td>
<td><?=$cname?></td>
<td><?=$scity?></td>
<td><?=$cstate?></td>
<td><?=$gcode?></td>
</tr>
<?
}
?>
</table>

Posted: Mon Sep 29, 2003 3:12 pm
by Unipus
So make the column headers links with GET variables embedded in them, like:

<a href="#?sort_by=city&order=desc">City</a>

and then set up your SQL query to use those variables in the ORDER BY clause.