使用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.

查看全部
dongmaqiu6084
dongmaqiu6084
2014/12/03 16:24
  • php
  • mysql
  • jquery
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复