jquery表分类器未排序


jquery tablesorter not sorting

你好我被jquery表分类器卡住了:http://tablesorter.com/docs/index.html#Examples

如果某位jquery大师能检查我的代码,看看我哪里出了问题,我将不胜感激。它不是每页显示10条记录,而是显示所有记录,而且当我尝试对其进行排序时,它什么也不做。除此之外,没有出现斑马条纹。所有库都已加载,firebug中没有任何错误。非常感谢你的帮助。

<?php
$q=$_GET["q"];
$con = mysql_connect('localhost', 'root', '');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("sample", $con);
$sql="SELECT * FROM logger_log WHERE idusr_log = '".$q."' order by datein_log desc";
$result = mysql_query($sql);
echo "<table id='"userlog'" class='"tablesorter'">
<thead>
<tr>
<th align='"left'">Ip Address</th>
<th align='"left'">Date In</th>
<th align='"left'">Date Out</th>
</tr>
</thead>";
while($row = mysql_fetch_array($result))
  {
  echo "<tbody>";
  echo "<tr>";
  echo "<td>" . $row['ip_log'] . "</td>";
  echo "<td>" . date('d/m/Y H:i:s',strtotime($row['datein_log'])) . "</td>";
  echo "<td>" . date('d/m/Y H:i:s',strtotime($row['dateout_log'])) . "</td>";
  echo "</tr>";
  echo"</tbody>";
  }
echo "</table>";

mysql_close($con);
?>
<div id="pager" class="pager">
    <form>
        <img src="css/blue/first.png" class="first"/>
        <img src="css/blue/prev.png" class="prev"/>
        <input type="text" class="pagedisplay"/>
        <img src="css/blue/next.png" class="next"/>
        <img src="css/blue/last.png" class="last"/>
        <select class="pagesize">
            <option selected="selected"  value="10">10</option>
            <option value="20">20</option>
            <option value="30">30</option>
            <option  value="40">40</option>
        </select>
    </form>
</div>
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery.tablesorter.min.js"></script>
<script type="text/javascript" src="js/jquery.tablesorter.pager.js"></script>
<link href="css/blue/style.css" rel="stylesheet" type="text/css" />
        <script>
        $(document).ready(function()     
        {   
            $("#userlog")
            .tablesorter({widthFixed: true, widgets: ['zebra']})     
            .tablesorterPager({container: $("#pager")});     
        } );
        </script>

您需要从结果循环中移除<tbody>,并将其放置在while循环周围。

echo "<tbody>";
  while($row = mysql_fetch_array($result)) {  
    echo "<tr>";
      echo "<td>" . $row['ip_log'] . "</td>";
      echo "<td>" . date('d/m/Y H:i:s',strtotime($row['datein_log'])) . "</td>";
      echo "<td>" . date('d/m/Y H:i:s',strtotime($row['dateout_log'])) . "</td>";
    echo "</tr>";  
  }
  echo"</tbody>";
echo "</table>";

尝试从while循环中取出tbody标记,改为执行以下操作:

echo "<table id='"userlog'" class='"tablesorter'">
<thead>
<tr>
<th align='"left'">Ip Address</th>
<th align='"left'">Date In</th>
<th align='"left'">Date Out</th>
</tr>
</thead>
<tbody>";

然后在while循环之后:

echo "</tbody></table>";