douyi5157 2013-08-28 13:49
浏览 65
已采纳

jQuery tablesorter不起作用

The table is diplayed normal but can not sort it. Both .js files are in the same directory as the .php file itself.

<html>
<head>
<script src="jquery-1.6.2.js" type="text/javascript"></script>
<script src="jquery.tablesorter.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function() {
    $("#tabel").tablesorter();
    });
</script>
</head>
<body>

<?php

$con = pg_connect("user=bct password=bct host=localhost port=5432 dbname=users ") or die (pg_last_error());
$query = "SELECT * from users";
$result = pg_query($con, $query);


$t = '<table id="tabel" class="tablesorter">';

$t .= '<thead>';
//next code get column names
for($i=0; $i < pg_num_fields($result); $i++){
    $field_info = pg_field_name($result, $i);
    $t .= '<th>' . $field_info .  '</th>';
}
$t .= '</thead>';


//next code fetch cell content
$t .= '<tbody>';

while ($row=pg_fetch_row($result)){
    $t .= '<tr>';
    foreach($row as $_column){
    $t .= '<td>' .$_column. '</td>';
    $temp=$row;
    }
    $t .= '</tr>';
}

$t .= '</tbody></table>';

echo $t;

pg_close($con);
?>
</body>
</html>
  • 写回答

1条回答 默认 最新

  • dtuy84033 2013-08-28 13:52
    关注

    Give this a shot:

    $t .= '<thead><tr>';
    //next code get column names
    for($i=0; $i < pg_num_fields($result); $i++){
        $field_info = pg_field_name($result, $i);
        $t .= '<th>' . $field_info .  '</th>';
    }
    $t .= '</tr></thead>';
    

    I basically wrapped your <th>'s in a <tr>, going off of the example code here: http://tablesorter.com/docs/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事: