dongmaqiu6084 2014-12-03 16:24
浏览 46
已采纳

使用tablesorter的Jquery,php,mysql表排序

I'm doing a very simple site on which I need to have a table sorting system, I've got the table set up, it feeds back data from MySQL table but I cannot seem to be able to sort rows, any ideas?

<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href="main.css"/>
<title>Assessment 2</title>
    <script type="text/javascript" src="jquery-1.11.1.min.js"></script> 
    <script type="text/javascript" src="jquery.tablesorter.js"></script> 
    <script type ="text/javascript">

        $(document).ready(function() 
            { 
                $("products").tablesorter(); 
            } 
        ); 
    </script>
</head>
<body>
    <?php
      include '
avigation
avigation.php';
    ?>

<div class="center">
    <h1>Products</h1>



    <?php
        include "connectionlocalhost.php";


        $query = "SELECT * FROM products";
        $result = mysqli_query($connection, $query) or exit ("Error $query . ".mysqli_error());

            echo "<table border='1' id='products' class='tablesorter'>
            <thead>
                <tr>
                    <th>Product Name</th>
                    <th>Product Price</th>
                    <th>Product Image</th>
                </tr>
                </thead>
                <tbody>";   

        while ($row = mysqli_fetch_assoc($result)){
            echo "<tr>";
            echo "<td>". $row['productname'] . "</td>";
            echo "<td>". $row['productprice'] . "</td>";
            echo "</td>";

            }
            mysqli_free_result($result);



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

    ?>
</div>

</body>
</html>

I am aware that one of columns is empty, its just for testing purposes, I thought there was an error with mysql query.

  • 写回答

1条回答 默认 最新

  • douhuocuo9012 2014-12-03 16:36
    关注

    You need to add the pound sign # to "products" for:

    $("products").tablesorter();
    

    in regards/reference to the table's "id"

    <table border='1' id='products' class='tablesorter'>
    

    change that to:

    $("#products").tablesorter(); 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 我这模型写的不对吗?为什么lingo解出来的下面影子价格这一溜少一个变量
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波