Okay, so I have a page that displays a table listing all the books that I have Read. A user can check a checkbox off next to each one. If they submit it the books are added to a different database. Anyways, what I need help with it is allowing the user to order the table by the columns that are shown here (on the same page). I want to just make the column titles hyperlinks at which point they can select a column heading, it'll reload the page sorted by that heading. Reverse order would be nice on second click, but not needed.
I look around for tutorials for this, but couldn't find any or at least not ones that were simple enough for me to understand and apply to my own. Help is greatly appreciated!
My code for the page:
<html>
<body>
<?php
global $user;
$db = mysql_connect("localhost", "collin","MYPASSWORD");
mysql_select_db("mydatabase_name",$db);
//add books to database that are checked
$query="SELECT a.book, a.rarity, a.price, a.sid FROM collector_books a LEFT JOIN collector_books_read b ON a.sid = b.sid and b.uid = $user->uid WHERE b.sid IS NULL";
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
$sid=mysql_result($result,$i,"sid");
if($_REQUEST[$sid] == "on")
mysql_query("INSERT INTO collector_books_read VALUES ($sid, $user->uid)");
$i++;
}
//display all non-read books for user to select which ones he has read
$query="SELECT a.book, a.rarity, a.price, a.sid FROM collector_books a LEFT JOIN collector_books_read b ON a.sid = b.sid and b.uid = $user->uid WHERE b.sid IS NULL ORDER BY a.book ASC";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
echo "<center>Book Collector Checklist</center>
";
echo '<form name="form1" method="post" action="">';
echo "<table align='center' border=1 cellpadding=4 cellspacing=0>";
echo "<tr><td>Book</td><td>Rarity</td><td>Price</td><td>Read</td></tr>";
$i=0;
while ($i < $num) {
$book=mysql_result($result,$i,"book");
$rarity=mysql_result($result,$i,"rarity");
$price=mysql_result($result,$i,"price");
$sid=mysql_result($result,$i,"sid");
$checkbox="<input type='checkbox' name='$sid'>";
echo "<tr><td>$book</td><td>$rarity</td><td>$price</td><td>$checkbox</td></tr>";
$i++;
}
echo "</table>";
echo '<center><input type="submit" name="Submit" value="Mark as Read"></center>';
echo '</form>';
?>
</body>
</html>