我有一个可以产生数千个结果的大型数据库,我需要限制分页链接的数量,比如 9 个链接,前 4 页在一侧,然后是当前页面,然后是 4 个下一页。
例如:14|15|16|17| 18 |19|20|21|22 有谁知道我如何做到这一点?谢谢
if (isset($_GET["page"]))
{
$page = $_GET["page"];
}
else
{
$page=1;
};
$start_from = ($page-1) * 10;
$message = "SELECT * FROM document WHERE email='$_SESSION[email]' ORDER BY id DESC LIMIT $start_from , 10";
// echo results
// make page links for results
$sql = "SELECT id FROM document WHERE email = '$_SESSION[email]'";
$rs_result = $db->query($sql);
$total_records = $rs_result->num_rows;
$total_pages = ceil($total_records / 10);
if($rs_result->num_rows >10) {
$page = "<p class = 'page'>";
for ($i=1; $i<=$total_pages; $i++)
{
$page .="<a href='results.html?page=".$i."'>".$i."</a> ";
}
$page .="</p>";
echo $page;
}