jQuery插件DataTables将无法连接到数据库

时间:2016-06-10 14:16:46

标签: jquery sql datatables

我一直在研究这个问题,所以任何建议都值得赞赏。我正在创建一个表格,用户可以在其中输入产品和其他产品信息。我正在使用名为DataTables(https://datatables.net/)的jQuery插件。所有看起来都是,但它就像列出的数据没有连接到插件。您无法对任何内容进行排序或搜索任事实上,它表示零输入显示零。这是它的样子:

Screen shot of DataTables plugin

以下是我的所有代码:

<?php
session_start();

include_once("db.php");

$sql_prod = "SELECT * FROM products ORDER BY id ASC";
$results = mysqli_query($db,$sql_prod) or die(mysqli_error());
$product = "";
?>

<!DOCTYPE html>
<html lang="en">
<div class="container">
<html>
    <head>
        <title></title>
        <meta charset="utf-8">
          <meta name="viewport" content="width=device-width, initial-scale=1">
          <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
          <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
          <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

        <script src="jquery-1.12.4.js"></script>
        <link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css" />
        <script type="text/javascript" src="//cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>

        <script type="text/javascript">     
            $(document).ready(function(){
            $('#products_table').DataTable();
            });
        </script>  
    </head>

    <body>
        <div>
            <table id="products_table">
                <thead>
                    <tr>
                        <th>Product Name</th>
                        <th>Product Description</th>
                        <th>Tax free price</th>
                        <th>Costs</th>
                        <th>Sales margin</th>
                        <th>Sales %</th>
                        <th>Edit</th>
                        <th>Delete</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    if (mysqli_num_rows($results)>0) {
                        while ($row=mysqli_fetch_assoc($results)){
                            $id = $row['id'];
                            $prodName = $row['prodName'];
                            $prodDesc = $row['prodDesc'];
                            $taxFree = $row['taxFree'];
                            $prodCost = $row['prodCost'];
                            $salesMargin = $row['salesMargin'];
                            $salesPercent = $row['salesPercent'];

                        $product .="
                            <tbody>
                                <tr>
                                    <td>$prodName</td>
                                    <td>$prodDesc</td>
                                    <td>$taxFree</td>
                                    <td>$prodCost</td>
                                    <td>$salesMargin</td>
                                    <td>$salesPercent</td>
                                    <td><a href='#'>Edit</a></td>
                                    <td><a href='#'>Delete</a></td>                         
                                </tr>
                            </tbody>";                      
                        }
                            echo $product;                  
                    }
                    ?>

                </tbody>
            </table>
        </div>  
    </body>
    </html>
    </div>

任何建议,即使是疯狂的建议,我也会尝试。非常感谢!

0 个答案:

没有答案