[英]PHP pagination with page numbers
I have code that I have used on several sites to deal with pagination. 我有在几个站点上用于处理分页的代码。 The problem I'm facing is that the code only give 'next' and 'previous' links. 我面临的问题是该代码仅提供“下一个”和“上一个”链接。 For the site I am working on I need page numbers too, not them all, maybe 5 at a time, kin of like this < 1 2 3 4 5 > then when you get to page 5 < 6 7 8 9 10 > 对于我正在处理的站点,我也需要页码,而不是全部,一次只需要5个,类似这样的<1 2 3 4 5>然后转到第5页<6 7 8 9 10>
This is my pagination code so farf 这是我的分页代码
//paganation settings
$pages_query = mysqli_query($link, "SELECT COUNT(`id`) FROM `products` WHERE subcat = 1 AND
status = 1") or die(mysqli_error($link));
$result = mysqli_fetch_array($pages_query, MYSQLI_NUM);
$pages = $result[0] / $per_page;
$page = (isset($_GET['page']) AND (int)$_GET['page'] > 0) ? (int)$_GET['page'] : 1;
$start = ($page - 1) * $per_page;
$last = ($pages - 1) / $per_page;
$prev = $page - 1;
$next = $page + 1;
//query the db
$q =mysqli_query($link, "SELECT * FROM products WHERE subcat = 1 AND status = 1
ORDER BY id DESC LIMIT $start, $per_page");
if(mysqli_num_rows($q) > 0){
//find out the page we are on and display next and previous links accordingly
if ($page >= 1){
if ($page < $pages) {
echo "<span class='next'>";
echo "<a href=\"?page={$next}\">Next</a> ";
echo "</span>";
}
if ($page >=2){
echo "<span class='prev'>";
echo "<a href=\"?page={$prev}\">Back</a> ";
echo "</span>";
}
}
else if ($page > $pages + 1){
echo 'No more images in the database';
}
Can anyone help me add the page numbers in here 谁能帮我在这里添加页码
Thanks 谢谢
for ($i=1; $i<=$total_pages; $i++) {
$pagLink .= "<a href='index.php?page=".$i."'>".$i."</a>";
};
This might hel you put it between if loops for next and prev page 这可能会帮助您将它放在下一页和上一页的if循环之间
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.