【发布时间】:2017-08-20 00:27:15
【问题描述】:
我正在从 PHP 表引导程序中的数据库数据中获取数据。我想要的是现在进行分页,因为我得到的表格很长,我想要例如 6 行/页。这是我使用 DataTables 插件的代码,但它不起作用:/ 谁能帮助我?
<html>
<!-- DataTables CSS -->
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.7/css/jquery.dataTables.css">
<!-- jQuery -->
<script type="text/javascript" charset="utf8" src="//code.jquery.com/jquery-1.11.1.min.js"></script >
<!-- DataTables -->
<script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.7/js/jquery.dataTables.js"></script>
<div class="container">
<div class="row vertical-center-row">
<div class="col-lg-12">
<div class="row">
<div class="table-responsive">
</div>
</div>
</div>
</div>
<div class="col-xs-4 col-xs-offset-4">
<table id="table" class="table table-striped" cellspacing="0" width="100%">
<h3>Update/Remove Access Rights</h3>
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Surname</th>
<th>Nickname</th>
<th> Door Description </th>
</tr>
</thead>
<tbody>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#table').dataTable( {
"pagingType": "full_numbers"
} );
} );
</script>
<?php
$stmt="select id_access_rights,name,surname,nickname, description
from users
join access_rights on users.rfidcode=access_rights.users_rfidcode
join doors
on doors.id_doors=access_rights.doors_id_doors
order by name ";
$result=$conn->query($stmt);
if($result === FALSE) {
die(mysqli_error()); // TODO: better error handling
}
while($row =$result->fetch_assoc()){
$f1=$row['id_access_rights'];
$f2=$row['name'];
$f3=$row['surname'];
$f4=$row['nickname'];
$f5=$row['description'];
?>
<tr>
<td><?php echo $f1 ?>
<td><?php echo $f2 ?>
<td><?php echo $f3 ?>
<td><?php echo $f4 ?>
<td><?php echo $f5 ?>
<td><?php echo "<a href='updateAccessRights.php?id_access_rights=" . htmlentities($f1). "'>Update";?>
<td><?php echo "<a href='deleteAccessRights.php?id_access_rights=" . htmlentities($f1). "'>Remove";?>
</td>
<?php
}
?>
</tr>
</table>
</tbody>
</table>
<br>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
【问题讨论】:
-
通常对于仅使用 PHP 的分页,我会在查询中添加一个“限制”,以选择一个起点并限制多少个结果。如果限制为 5,则应该有两个变量。页 ($_GET['page']) 和限制 ($limit)。要获取起点,请使用 (($_GET['page'] - 1) * $limit)。在您的查询中使用这些变量。
-
我怎样才能将它们添加到查询中只有两个变量?
-
显示未定义变量页面
-
如果 $offset = ($_GET['page'] - 1) * $limit 在查询中添加“limit $offset, $limit”
-
在这种情况下,什么样的值变成 $limit ?在您的问题中,它没有定义。还有可变页面呢?
标签: php pagination html-table