I'm currently working on a small project where I have an SQL Database that holds some data which I want to display in sortable tables.
I have already set up a Website which displays the tables. My problem is getting tablesorter working on these tables.
The website (http://tablesorter.com/) just gives an example for a single table.
Here's my sourcecode that's generated by PHP:
The code snippet which generates the tables is this:
while ($row = mysqli_fetch_array($selectedtanks)) {
$tank_id = $row[tank_id];
echo "<h2> ".tank_id2name($row[tank_id])." </h2><br>";
echo
"<table class=\"tablesorter\" id=\"myTable\">
<thead>
<tr>
<td>Nickname</td>
<td>Damage</td>
<td>Frags</td>
<td>Spots</td>
<td>Wins</td>
<td>Battles</td>
</tr>
</thead>
";
$sql = "select * from user2rooms left join usertanks on user2rooms.account_id=usertanks.account_id where user2rooms.room_id='$room_id' AND usertanks.tank_id='$tank_id'";
$result = mysqli_query($db,$sql);
while ($row2 = mysqli_fetch_array($result)) {
echo "<tbody>
<tr>
<td>".account_id2name($row2[account_id])."</td>
<td>".round($row2[damage_dealt]/$row2[battles],2)."</td>
<td>".round($row2[frags]/$row2[battles],2)."</td>
<td>".round($row2[spotted]/$row2[battles],2)."</td>
<td>".round($row2[wins]/$row2[battles],4)*100 ."%</td>
<td>".$row2[battles]."</td>
</tr>
</tbody>
</table>
";
}
}
Code where JS get's added:
<head>
<script type="text/javascript" src="/jquery/jquery-latest.js"></script>
<script type="text/javascript" src="/jquery/jquery.tablesorter.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript">
$(document).ready(function()
{
$(".tablesorter").css("border", "3px solid red");
}
);
</script>