我正在做一个非常简单的网站,我需要一个表排序系统,我已经设置了表,它从 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/