how do i sort a table by clicking on the header link?
I tried doing this but it involves too many files (one for each sortable columns).
what are the other (better) ways to do this?
also how to alternate the order (ascending/desending) with every click
thanks
Code:
page1.php
if(isset($_SESSION['test5']))
{
$result = mysql_query($_SESSION['test']);
}
else
{
$result = mysql_query("SELECT * FROM student"); //default
}
echo "<table>";
echo "<tr class='header'>";
echo "<td>";
echo "<a href='testing.php'>ID</a>";
echo "</td>";
echo "<td>";
echo "<a href='testing2.php'>NAME</a>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "</tr>";
echo "</table>";
Code:
testing.php
<?php session_start();
$_SESSION['test5'] = "SELECT * FROM STUDENT ORDER BY id";
header('LOCATION: page1.php');
?>
Code:
testing2.php
<?php session_start();
$_SESSION['test5'] = "SELECT * FROM STUDENT ORDER BY name";
header('LOCATION: page1.php');
?>