我有一个页面,上面有带有数据库的数据表,数据表本身工作正常,但我的问题是,当我重新加载/刷新我的页面时,该数据表中的所有记录都显示它不应该显示所有记录,因为在我的数据表中有一个分页,但每次我重新加载/刷新我的页面时它总是显示所有记录并且当重新加载/刷新完成时数据表再次进入正常状态。我的问题是在重新加载/刷新页面时..
这是我的代码 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。
关于jquery - 使用 PDO、CSS 和 JQUERY 的数据表问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36993843/