我有一个页面,上面有带有数据库的数据表,数据表本身工作正常,但是我的问题是,当我重新加载/刷新页面时,该数据表中的所有记录都显示出来,因此不应该显示所有记录,因为在我的数据表中有一个分页,但是每次我重新加载/刷新页面时,它总是显示所有记录,并且当重新加载/刷新完成时,数据表再次回到正常状态。我的问题是重新加载/刷新页面时。
这是我的代码 index.php
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/jquery-2.1.3.min.js"></script>
<link type="text/css" rel="stylesheet" href="datatable/media/css/jquery.dataTables_themeroller.css">
<link type="text/css" rel="stylesheet" href="datatable/media/css/jquery.dataTables.css">
<script type="text/javascript" src="datatable/media/js/jquery.js"></script>
script.js
$(document).ready(function(){
$('.table-bordered').dataTable({
"scrollY": "300px", //Scroll vertical
"scrollX": "true", //Scroll Horizontal
"iDisplayLength": 20, //Display 20 records Per Page
"scrollCollapse": true,
"paging": true //Pagination
});
});
的CSS
.table_wrapper{
margin-top:5px;
max-width:100%;
width:100%;
margin-bottom:60px;
overflow:auto;
-webkit-box-shadow: 0 8px 30px -6px black;
-moz-box-shadow: 0 8px 30px -6px black;
box-shadow: 0 8px 30px -6px black;
height:auto;
}
.table-bordered{
border-collapse:collapse;
margin-right: auto;
margin-left: auto;
font-size: 13px;
}
thead th{
background-color:#6a782a;
color:#FFF;
padding-left: 10px;
padding-right: 10px;
}
tbody td{
word-wrap: break-word;
}
这是我的身体/桌子的代码
<div class="table_wrapper">
<table class="table table-bordered" width="100%">
<thead>
<tr>
<th>ID</th>
<th>LO Name</th>
<th>Province</th>
<th>Location</th>
<th>Title Number</th>
<th>Lot Number</th>
<th>Survey Number</th>
<th>Module Number</th>
<th>Land Type</th>
<th>Area</th>
<th>Remarks</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT * FROM survey_section";
$crud->dataview($query);
?>
</tbody>
</table>
</div>
$query = "SELECT * FROM survey_section";
不是分页的方法。
使用PDO的一种方法是
$sql = "SELECT * FROM `survey_section` LIMIT ?, ?";
$stmt = $dbh->prepare($sql);
$stmt->bindValue(1,$offset, PDO::PARAM_INT);
$stmt->bindValue(2,$rowsperpage, PDO::PARAM_INT);
其中$ offset是页码,在您的情况下,从$ POST []或GET []和$ rowsperpage到第20页的整个长度。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句