我使用dataTable插件来格式化我的html表。但是它没有显示我想要的结果。它显示所有记录而不是每页10条记录。我使用了iDisplayLength:10但它也不起作用。
我的代码: -
<html>
<head>
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="https://cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function(){
$('#count').DataTable({
"pagingType": "full_numbers",
"iDisplayLength": 10
}
);
});
</script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.4/css/jquery.dataTables.min.css">
</head>
<table id="count">
<thead>
<tr>
<th>Quarter ID</th>
<th>Locality Name</th>
<th>Block</th>
<th>Floor</th>
<th>RB Type</th>
<th>Quarter Type</th>
<th>Quarter No</th>
<th>No of Rooms</th>
<th>Servant quarter</th>
<th>Status</th>
</tr>
</thead>
<?php
require 'connection.php';
$q8="select * from mstquarters";
$q9=mysqli_query($con,$q8);
if(mysqli_num_rows($q9)>=1)
{
while($row=mysqli_fetch_array($q9))
{
?>
<?php
$y=$row['blockId'];
$q5="select * from mstblocks where blockId='$y'";
$r5=mysqli_query($con,$q5);
$r6=mysqli_fetch_array($r5);
$r7=$r6['block'];
$z=$row['localityId'];
$q6="select * from mstlocalities where localityId='$z'";
$s5=mysqli_query($con,$q6);
$s6=mysqli_fetch_array($s5);
$s7=$s6['localitySName'];
?>
<tbody>
<tr>
<td><?php echo $row['quarterId'];?></td>
<td><?php echo $s7;?></td>
<td><?php echo $r7;?></td>
<td><?php echo $row['floor'];?></td>
<td><?php echo $row['rbType'];?></td>
<td><?php echo $row['quarterType'];?></td>
<td><?php echo $row['quarterNo'];?></td>
<td><?php echo $row['noOfRooms'];?></td>
<td><?php echo $row['servantQuarter'];?></td>
<td><?php echo $row['status'];?></td>
</tr>
</tbody>
<?php
}
}
?>
</table>
</html>
我已经包含了javascript文件,我应该包含更多文件以便正常工作吗?
答案 0 :(得分:1)
问题是您在<tbody>
内创建while()
,这会导致错误的表格结构。
将它放在while()
之外,你会很高兴
像这样: -
</thead>
<tbody>
<?php
require 'connection.php';
$q8="select * from mstquarters";
$q9=mysqli_query($con,$q8);
if(mysqli_num_rows($q9)>=1)
{
while($row=mysqli_fetch_array($q9))
{
?>
<?php
$y=$row['blockId'];
$q5="select * from mstblocks where blockId='$y'";
$r5=mysqli_query($con,$q5);
$r6=mysqli_fetch_array($r5);
$r7=$r6['block'];
$z=$row['localityId'];
$q6="select * from mstlocalities where localityId='$z'";
$s5=mysqli_query($con,$q6);
$s6=mysqli_fetch_array($s5);
$s7=$s6['localitySName'];
?>
<tr>
<td><?php echo $row['quarterId'];?></td>
<td><?php echo $s7;?></td>
<td><?php echo $r7;?></td>
<td><?php echo $row['floor'];?></td>
<td><?php echo $row['rbType'];?></td>
<td><?php echo $row['quarterType'];?></td>
<td><?php echo $row['quarterNo'];?></td>
<td><?php echo $row['noOfRooms'];?></td>
<td><?php echo $row['servantQuarter'];?></td>
<td><?php echo $row['status'];?></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
答案 1 :(得分:0)
尝试"_iDisplayLength": 10
或将jquery.dataTables.js添加到您的项目中。
因为iDisplayLength
位于 jquery.dataTables.js
答案 2 :(得分:0)
使用$ _REQUEST [“start”]和$ _REQUEST [“length”] $ _REQUEST [“start”]默认以0开头,$ _REQUEST [“length”]在下面设置iDisplayLength。 $( '#计数')。数据表({ “pagingType”:“full_numbers”, “iDisplayLength”:10 } 拿两个变量 $开始= $ _ REQUEST [ “开始”]; $长度= $ _ REQUEST [ “长度”];
并在此处使用----从mstquarters限制$ start,$ length
中选择*答案 3 :(得分:0)
jquery代码中的任何变化
在php文件中添加代码。
取两个变量
$开始= $ _ REQUEST [ “开始”]; $长度= $ _ REQUEST [ “长度”];
并在此处使用----从mstquarters限制$ start,$ length
中选择*