du0923 2017-01-05 19:55
浏览 92

使用Tablesorter对从动态SQL查询生成的表进行排序

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:

Link

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>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 matlab求解平差
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料
    • ¥15 使用R语言marginaleffects包进行边际效应图绘制
    • ¥20 usb设备兼容性问题
    • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
    • ¥15 安装svn网络有问题怎么办
    • ¥15 vue2登录调用后端接口如何实现
    • ¥85 永磁型步进电机PID算法