Jump to content

Sort by table column


NoDoze

Recommended Posts

ok, I search these forums for answers but each solution was different, and from the looks of it, the code contained shortcuts....cause it doesn't make sense to me...I don't get it...SO, I'm going to post my code, and hopefully someone could help me :)

I need these columns, when the header is clicked, the column is sorted by that header.

[code]
<html>
<head>
<style type="text/css">
<!--
a:link , a:visited {
color: #FFFFFF;
text-decoration: none;
}
a:hover {
color: #000000;
text-decoration: none;
}
.table {
font-family: Arial;
font-size: 12px;
color: #FFFFFF;
text-decoration: none;
text-align: center;
border: 1px solid #FFFFFF;
width: 100%;
}
.table-header {
font-family: Arial;
font-size: 12px;
font-weight: bold;
color: #FFFFFF;
text-decoration: none;
text-align: center;
background-color: #0554A3;
}
.tf {
background-color: #3399CC;
}
-->
</style>
</head>
<body>
<table class="table">
<tr class="table-header">
<td><a href="pil-view.php?sortby=id">ID</a></td>
<td><a href="pil-view.php?sortby=date">Initiation Date</a></td>
<td><a href="pil-view.php?sortby=project_number">Project Number</a></td>
<td><a href="pil-view.php?sortby=resposible_individual">Responsible Individual</a></td>
<td><a href="pil-view.php?sortby=project_description">Project Description</a></td>
<td><a href="pil-view.php?sortby=country">County</a></td>
<td><a href="pil-view.php?sortby=region">Region</a></td>
<td><a href="pil-view.php?sortby=client">Client</a></td>
</tr>

</body>
</html>
<?
include 'config.php';
include 'opendb.php';

$query="SELECT * FROM pil";
$result=mysql_query($query);

mysql_close();

$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
$id=mysql_result($result,$i,"id");
$date=mysql_result($result,$i,"date");
$project_number=mysql_result($result,$i,"project_number");
$resposible_individual=mysql_result($result,$i,"resposible_individual");
$project_description=mysql_result($result,$i,"project_description");
$county=mysql_result($result,$i,"county");
$region=mysql_result($result,$i,"region");
$client=mysql_result($result,$i,"client");

// alternate #8F8F8F with #000000

print ($i % 2) ? "<tr bgcolor=\"6699CC\">" : "<tr bgcolor=\"3399CC\">";

print "<td>$id</td>";
print "<td>$date</td>";
print "<td>$project_number</td>";
print "<td>$resposible_individual</td>";
print "<td>$project_description</td>";
print "<td>$county</td>";
print "<td>$region</td>";
print "<td>$client</td>";

++$i;
}

include 'closedb.php';
?>

[/code]

Any help is appreciated, thanks!
Link to comment
https://forums.phpfreaks.com/topic/29982-sort-by-table-column/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.