I am trying to make the following code sortable by clicking any of the column headings in the table. I know how to do it by changing my query, but how can i do it fter the fact?
something like the default sort is b_name but if i click heading 'Level' resort by b_lvl
i feel like im going in the wrong direction and any help would be great!
FYI this is for a game
Thanks
-Rich
(not the cleanest code i know)
$dbh=mysql_connect ("localhost", "rbanke_online", "*****") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("rbanke_online");
$bbquery = 'SELECT * FROM fsblackbook GROUP BY b_name';
$result = mysql_query($bbquery) or die('Query failed: ' . mysql_error());
$color1 = "#3A3A3A";
$color2 = "#292929";
$row_count = 0;
echo "<table width='95%' border='0' align='center' cellpadding='2' cellspacing='1'>";
echo "<tr bgcolor='#1F1F1F'>";
echo "<th rowspan='2'><div align='center'>Name</div></th>";
echo "<th><div align='center'>Deaths</div></th>";
echo "<th><div align='center'>";
echo "Level</div></th>";
echo "<th><div align='center'>Residence</div></th>";
echo "<th rowspan='2'><div align='center'>Last Login</div></th>";
echo "<th rowspan='2'><div align='center'>Reason</div></th>";
echo "<th rowspan='2'><div align='center'>Date Added</div></th>";
echo "<th rowspan='2'><div align='center'>Recent Deaths</div></th>";
echo "</tr>";
echo "<tr bgcolor='#1F1F1F'>";
echo "<th><div align='center'>Fine</div></th>";
echo "<th><div align='center'>Voc</div></th>";
echo "<th>Acct Stat </th>";
echo "</tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
// Print out the contents of each row into a table
$row_color = ($row_count % 2) ? $color1 : $color2;
echo "<tr bgcolor='$row_color'>";
echo "<td rowspan='2'><div align='center'>";
echo '<A HREF="http://www.tibia.com/community/?subtopic=character&name=', urlencode($row['b_name']), '" target= _blank>', $row['b_name'], '</A>';
echo "</div></td>";
echo "<td><div align='center'><font color='#FF0000'>";
echo $row['b_deaths'];
echo "</font></div></td>";
echo "<td><div align='center'>";
echo $row['b_lvl'];
echo "</div></td>";
echo "<td><div align='center'>";
echo $row['b_residence'];
echo "</div></td>";
echo "<td rowspan='2'><div align='center'>";
echo "<DIV align=center>";
echo $row['b_lastlog'];
echo "</DIV>";
echo "</div></td>";
echo "<td rowspan='2'><div align='center'>";
echo $row['b_reason'];
echo "</div></td>";
echo "<td rowspan='2'><div align='center'>";
echo $row['b_added'];
echo "</div></td>";
echo "<td rowspan='2'><div align='center'>";
echo $row['b_kills'];
echo "</div></td>";
echo "<tr bgcolor='$row_color'>";
echo "<td bgcolor='$row_color'><div align='center'>";
echo $row['b_fine'];
echo "k</div></td>";
echo "<td bgcolor='$row_color'><div align='center'>";
echo $row['b_voc'];
echo "</div></td>";
echo "<td bgcolor='$row_color'><div align='center'>";
echo $row['b_acctstat'];
echo "</div></td>";
echo "</tr>";
echo "<tr bgcolor='#1F1F1F'>";
echo "<td height='5px' colspan='8'><div align='center'></div><div align='center'></div><div align='center'></div><div align='center'></div><div align='center'></div><div align='center'></div><div align='center'></div><div align='center'></div></td>";
echo "</tr>";
$row_count++;
}
echo "</table>";