column sort

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
sulen
Forum Commoner
Posts: 79
Joined: Wed Jul 09, 2003 4:55 pm
Location: los angeles
Contact:

column sort

Post 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>
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post 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.
Post Reply