DataTables分页和搜索无法正常工作

时间:2016-09-14 23:44:15

标签: php jquery mysql datatable pagination

我有一个显示数据库数据的DataTable。它使用while循环来获取数据并在表中显示。但我现在遇到的问题是,数据库中的所有数据行都显示在表中,没有分页。因此,假设我在数据库中有100行数据,所有数据都出现在一个长表中,我将不得不继续向下滚动以查看数据库中的所有数据。这意味着每页显示的记录和分页不起作用。搜索和排序方面也不起作用。下面是我的代码和数据表的截图。请帮帮我,因为我已经堆积了。

<table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                <thead>
                                    <tr>
                                        <th>Event Date</th>
                                        <th>number</th>
                                        <th>Agent number</th>
                                        <th>Agent Name</th>
                                        <th>Remarks</th>
                                    </tr>
                                </thead>
                                <tbody>
                                <?php

                                $result = mysqli_query($conn,"SELECT * FROM roaming");
                                $count = mysqli_num_rows($result);

                                while($row=mysqli_fetch_array($result)){

                                ?>


                                    <tr class="">
                                        <td><?php echo $row['eventDate'];?></td>
                                        <td><?php echo $row['number'];?></td>
                                        <td><?php echo $row['agent_number'];?></td>
                                        <td class="center"><?php echo $row['service'];?></td>
                                        <td class="center"><?php echo $row['vpmn'];?></td>
                                    </tr>
                                    <?php   } //end of while loop ?>
                                </tbody>
                            </table>

DataTable屏幕截图enter image description here

1 个答案:

答案 0 :(得分:1)

您的SQL查询&#34; SELECT * FROM漫游&#34;例如,返回所有行,而不仅仅是前10行。

要获得前十行,您的SQL查询应该是这样的:

"SELECT * FROM roaming LIMIT 0,10"

要获取10到20之间的行(下一页),请使用如下查询:

"SELECT * FROM roaming LIMIT 10,10"
相关问题