[英]DataTables pagination and search not working
我有一个 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>
例如,您的 SQL 查询“SELECT * FROM roaming”返回所有行,而不仅仅是前 10 行。
要仅获取前十行,您的 SQL 查询应如下所示:
"SELECT * FROM roaming LIMIT 0,10"
要获取 10 到 20 行(用于下一页),请使用如下查询:
"SELECT * FROM roaming LIMIT 10,10"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.