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(); 
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题