这是一个学校项目,该页面显示了一个表格,该表格分为每页15个部分,但在表格的底部,它们是要转到哪一页的数字。
我的表有862450行,这意味着底部显示了57408个数字。我该如何将它限制在5个数字,使它看起来像这样
〈< 12345 >〉
任何帮助都非常感谢!
<div class="container mt-4">
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header">
<h4>List of Regulated Pools
</h4>
<div class="btn-group">
<a href="Databaseone.php" class="btn btn-primary active" aria-current="page"> Regulated Pool Register</a>
<a href="Databasetwo.php" class="btn btn-primary">Certified Safety Pools</a>
<a href="Databasethree.php" class="btn btn-primary">Registered Pool Inspectors</a>
</div>
</div>
<div class="card-body">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>ID</th>
<th>Site Name</th>
<th>Unit Number</th>
<th>Street Number</th>
<th>Street Name</th>
<th>Street Type</th>
<th>Suburb</th>
<th>Post Code</th>
<th>Nubmer of Pools</th>
<th>Local Goverment Authority</th>
<th>Shared Pool</th>
</tr>
</thead>
<tbody>
<?php
require('conn.php');
$num_per_page=15;
if(isset($_GET["page"]))
{
$page=$_GET["page"];
}
else
{
$page=1;
}
$start_from=($page-1)*15;
$query="select * from norm_pool limit $start_from,$num_per_page";
$result= mysqli_query($conn, $query);
if(mysqli_num_rows($result) > 1 )
{
while($row = $result->fetch_assoc())
{
?>
<tr>
<td><?= $row['ID']; ?></td>
<td><?= $row['sitename']; ?></td>
<td><?= $row['unitno']; ?></td>
<td><?= $row['streetno']; ?></td>
<td><?= $row['streetname']; ?></td>
<td><?= $row['streettype']; ?></td>
<td><?= $row['suburb']; ?></td>
<td><?= $row['postcode']; ?></td>
<td><?= $row['noofpools']; ?></td>
<td><?= $row['localgovauth']; ?></td>
<td><?= $row['sharedpool']; ?></td>
</tr>
<?php
}
}
else
{
echo "<h5> No Users Found </h5>";
}
?>
</tbody>
</table>
<?php
require('conn.php');
$query='select * from norm_pool';
$result= mysqli_query($conn, $query);
$total_records=mysqli_num_rows($result);
$total_pages=ceil($total_records/$num_per_page);
for($i=1;$i<=$total_pages;$i++)
{
echo "<a href='Databaseone.php?page=".$i."'>".$i."</a>";
}
?>
</div>
</div>
</div>
</div>
</div>
我已经尝试了多种解决方案,没有一个成功,因为所有的解决方案都有非常不同的代码给我
2条答案
按热度按时间e1xvtsh31#
这里有一个方法
请看下面的代码:
结果:(我相信你使用bootstrap,所以我添加了一些)
liwlm1x92#
要限制分页中显示的数字,您可以使用“省略号”或“点”的概念来指示除了当前显示的页面之外还有更多的页面可用。以下是您可以遵循的一些步骤:
1.确定在任何给定时间要显示的最大页数。
1.计算当前页面相对于总页数的位置。
1.如果当前页靠近分页的开头或结尾,则显示允许的最大页数。
1.如果当前页面位于中间,则显示允许的最大页数,用省略号或圆点表示还有更多可用页面。
1.当用户单击省略号时,更新分页以显示下一组页面。
例如,假设您希望在任何给定时间最多显示5页,并且您当前在总共20页中的第10页。分页将显示如下内容:
12 ... 910 11 .十九二十
省略号表示除了当前显示的页面之外还有更多可用的页面,当用户单击它时,分页将更新以显示下一组页面。