javascript - dataTable 插件不工作,它在一页中显示所有记录,我每页只需要 10 条记录

标签 javascript php jquery html css

我使用 dataTable 插件来格式化我的 html 表格。但它没有显示我想要的结果。它显示所有记录而不是每页 10 条记录。我也使用 iDisplayLength: 10 但它不起作用。

我的代码:-

<html>
<head>
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="https://cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function(){
    $('#count').DataTable({
           "pagingType": "full_numbers",
           "iDisplayLength": 10
         }
    );
});
</script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.4/css/jquery.dataTables.min.css">
</head>
  <table id="count">
                <thead>
                 <tr>
                    <th>Quarter ID</th>
                    <th>Locality Name</th>
                    <th>Block</th>
                    <th>Floor</th>
                    <th>RB Type</th>
                    <th>Quarter Type</th>
                    <th>Quarter No</th>
                    <th>No of Rooms</th>
                    <th>Servant quarter</th>
                    <th>Status</th>
                 </tr>
                </thead>
                <?php
        require 'connection.php';
        $q8="select * from mstquarters";
        $q9=mysqli_query($con,$q8);
        if(mysqli_num_rows($q9)>=1)
        {
            while($row=mysqli_fetch_array($q9))
            {
                ?>
                <?php
                $y=$row['blockId'];
                $q5="select * from mstblocks where blockId='$y'";
                $r5=mysqli_query($con,$q5);
                $r6=mysqli_fetch_array($r5);
                $r7=$r6['block'];

                $z=$row['localityId'];
                $q6="select * from mstlocalities where localityId='$z'";
                $s5=mysqli_query($con,$q6);
                $s6=mysqli_fetch_array($s5);
                $s7=$s6['localitySName'];

                ?>
                <tbody>
                <tr>
                <td><?php echo $row['quarterId'];?></td>
                <td><?php echo $s7;?></td>
                <td><?php echo $r7;?></td>
                <td><?php echo $row['floor'];?></td>
                <td><?php echo $row['rbType'];?></td>
                <td><?php echo $row['quarterType'];?></td>
                <td><?php echo $row['quarterNo'];?></td>
                <td><?php echo $row['noOfRooms'];?></td>
                <td><?php echo $row['servantQuarter'];?></td>
                <td><?php echo $row['status'];?></td>
                </tr>
                </tbody>
                <?php
            }
        }
        ?>
    </table>
</html>

我已经包含了 javascript 文件,我是否应该包含更多文件才能正常工作?

最佳答案

问题是您正在创建 <tbody>里面while()这创建了错误的表结构。

放在while()之外你会很高兴去

像这样:-

</thead>
    <tbody>
        <?php
        require 'connection.php';
        $q8="select * from mstquarters";
        $q9=mysqli_query($con,$q8);
        if(mysqli_num_rows($q9)>=1)
        {
            while($row=mysqli_fetch_array($q9))
            {
                ?>
                <?php
                $y=$row['blockId'];
                $q5="select * from mstblocks where blockId='$y'";
                $r5=mysqli_query($con,$q5);
                $r6=mysqli_fetch_array($r5);
                $r7=$r6['block'];

                $z=$row['localityId'];
                $q6="select * from mstlocalities where localityId='$z'";
                $s5=mysqli_query($con,$q6);
                $s6=mysqli_fetch_array($s5);
                $s7=$s6['localitySName'];

                ?>
                <tr>
                <td><?php echo $row['quarterId'];?></td>
                <td><?php echo $s7;?></td>
                <td><?php echo $r7;?></td>
                <td><?php echo $row['floor'];?></td>
                <td><?php echo $row['rbType'];?></td>
                <td><?php echo $row['quarterType'];?></td>
                <td><?php echo $row['quarterNo'];?></td>
                <td><?php echo $row['noOfRooms'];?></td>
                <td><?php echo $row['servantQuarter'];?></td>
                <td><?php echo $row['status'];?></td>
                </tr>

                <?php
            }
        }
        ?>
    </tbody>
</table>

关于javascript - dataTable 插件不工作,它在一页中显示所有记录,我每页只需要 10 条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47195254/

相关文章:

php - Codeigniter MYSQL 连接作为单个记录返回?

php - 引擎盖下的继承

javascript - 用 jQuery 条件替换 CSS 属性

javascript - 领英群组 API

php - Imagick 3 writeImages() 函数不工作

javascript - 自动完成关闭错误

javascript - 使用 AJAX 和 JavaScript 从 API 访问 JSON 对象

javascript - 如何在 Yii 和 Ajax 中加载文章而不重新加载页面

javascript - 用于创建 SVG 图像/xml 的 PHP 脚本或类

javascript - 将匹配主题中相似或相同字符串的正则表达式模式