droxy80248 2014-04-09 14:20
浏览 48
已采纳

在一个部分上分配多个动态表

Hi I am totally stuck on this one. I am using tablesorter on data pulled from a mysql database. The problem is, based on criteria, I can have multiple tables pulled and displayed.

My problem is that tablesorter will only sort the first table instance.

This is the code I am using for the tablesorter. Basic use of it.

<script type="text/javascript" >
$(document).ready(function()
{
$("#table-2").tablesorter();
}

And this is how I pull the data and use it with tablesorter. It is the Branchname that can change. If a user is assigned more than one branch they get multiple tables. This is where I'm stuck on implementing tablesorter on any table past the first instance.

$result=mysql_query("SELECT id FROM users WHERE username='$username'");
$idary=mysql_fetch_assoc($result);
$id=$idary['id'];
$result0=mysql_query("SELECT branch_id FROM access WHERE userid='$id'");
while ($row1=mysql_fetch_assoc($result0))
{
$branch_id=$row1['branch_id'];
$result=mysql_query("select distinct(name) from location where id='$branch_id'");
$nameary=mysql_fetch_assoc($result);
$branchname=$nameary['name'];
?>
<table>
        <thead>
            <b><br><?echo $branchname; ?></b>
        </thead>
</table>
<div>
    <table id='table-2' class='tablesorter'>
        <thead>
            <tr>
                <thCreator</th>
                <th><center>TeamName</th>
                <th><center>Tech Tot</th>
                <th><center>Tot W/O</th>
                <th><center>Tot S/C</th>
            </tr>
        </thead>
    // get team creators from province
$result1=mysql_query("select distinct(teamcreator) from techteams where....

I'm thinking I would need to use some form of incrementing tablename to match the number of tables pulled but I'm stuck on how to do this. I could be wrong on that assumption and there might be a much easier way of doing this.

If anyone has any pointers in the right direction I'd love some tips.

Cheers, -Colin.

  • 写回答

2条回答 默认 最新

  • dongmang3961 2014-04-09 14:38
    关注

    you could try to give your tables an own class instead of an id.

    <table class='mytables'>
    
    <script type="text/javascript" >
    $(document).ready(function()
    {
      $(".mytables").tablesorter();
    }
    </script>
    

    or maybe only give them the table-sorter class and in your script you try something like this:

    $("table").tablesorter();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝