php - 使用tablesorter对jquery、php、mysql表进行排序

标签 php jquery mysql tablesorter

我正在做一个非常简单的网站,我需要一个表排序系统,我已经设置了表,它从 MySQL 表反馈数据,但我似乎无法对行进行排序,任何想法?

<!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 '\navigation\navigation.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>

我知道其中一列是空的,它只是为了测试目的,我认为 mysql 查询有错误。

最佳答案

您需要将井号 # 添加到“产品”中:

$("products").tablesorter();

关于/引用表的“id”

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

将其更改为:

$("#products").tablesorter(); 

关于php - 使用tablesorter对jquery、php、mysql表进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27276713/

相关文章:

javascript - Highcharts - 如何更改显示数据并删除鼠标悬停?

javascript - UIkit下拉菜单隐藏,如果通过javascript隐藏它又会再次出现

php - 在选择框中显示数据库的列

php - MySql 加载数据本地语法?

php - pg_prepare 创建角色的问题?

php - 如何处理 MySQLi fetch_all 结果?

php - 从多个时间段创建连续的时间线

php - 需要mysql select data where until的解决方案

javascript - JQuery:加载事件如何处理图像?

MySQL,混淆查询/错误代码 : 1111. 组函数的使用无效。