我想知道是否有人可以在我的商店中帮我解决一些分页问题。使用pajinate,我最初把它放在一起,但它似乎被窃听。我想添加一个'previous'和'back to begin'以及'next'和'last page'按钮。我尝试先实现'回到开始'和'上一步'按钮,但它们无法正常工作。如果有人可以帮助我一点点太棒了。在旁注中,我将此设置为一次显示10个数字的范围,但每次我点击更高的页码时,它会附加4-5个数字,对此问题的任何见解都将非常受欢迎。
<?php
// find out total pages
$totalpages = $resp->paginationOutput->totalPages;
echo "Total Results: ";
echo $totalpages.' pages ';
// get the current page or set a default
if (isset($_GET['pgno']) && is_numeric($_GET['pgno'])) {
// cast var as int
$currentpage = (int) $_GET['pgno'];
} else {
// default page num
$currentpage = 1;
} // end if
// if current page is greater than total pages...
if ($currentpage > $totalpages) {
// set current page to last page
$currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
// set current page to first page
$currentpage = 1;
} // end if
// the offset of the list, based on current page
$offset = ($currentpage - 1) * $entriesPerPage;
/****** build the pagination links ******/
// if not on page 1, don't show back links
if ($currentpage > 1) {
// show << link to go back to page 1
if(null!=$queryString){
// echo " <a href='{$_SERVER['PHP_SELF']}?$queryString¤tpage=1'><<</a> ";
}else{
// echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
}
// get previous page num
// $prevpage = $currentpage - 1;
// show < link to go back 1 page
// echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
} // end if
// range of num links to show
$range = 10;
// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
// if it's a valid page number...
if (($x > 0) && ($x <= $totalpages)) {
// if we're on current page...
if ($x == $currentpage) {
// 'highlight' it but don't make a link
echo " [<strong>$x</strong>] ";
// if not current page...
} else {
// make it a link
echo " <a href='".add_url_param('pgno',$x)."'>$x</a> ";
} // end else
} // end if
} // end for
?>
答案 0 :(得分:1)
你的prev页面被注释掉了,使用$ _GET ['currentpage']而不是$ _GET ['pgno'],这对我有用:
<?
$totalpages = 10;
if (isset($_GET['pgno']) && is_numeric($_GET['pgno'])) {
// cast var as int
$currentpage = (int) $_GET['pgno'];
} else {
// default page num
$currentpage = 1;
} // end if
echo $currentpage;
echo "/".$totalpages;
echo "<br />";
// if current page is greater than total pages...
if ($currentpage > $totalpages) {
// set current page to last page
$currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
// set current page to first page
$currentpage = 1;
} // end if
// the offset of the list, based on current page
$offset = ($currentpage - 1) * $entriesPerPage;
/****** build the pagination links ******/
// if not on page 1, don't show back links
if ($currentpage > 1) {
// show << link to go back to page 1
if(null!=$queryString){
echo " <a href='{$_SERVER['PHP_SELF']}?$queryString&pgno=1'><<</a> ";
}else{
echo " <a href='{$_SERVER['PHP_SELF']}?pgno=1'><<</a> ";
}
// get previous page num
$prevpage = $currentpage - 1;
// show < link to go back 1 page
echo " <a href='{$_SERVER['PHP_SELF']}?pgno=$prevpage'><</a> ";
} // end if
// range of num links to show
$range = 10;
// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
// if it's a valid page number...
if (($x > 0) && ($x <= $totalpages)) {
// if we're on current page...
if ($x == $currentpage) {
// 'highlight' it but don't make a link
echo " [<strong>$x</strong>] ";
// if not current page...
} else {
// make it a link
echo " <a href='".$_SERVER['PHP_SELF']."?pgno=$x"."'>$x</a> ";
} // end else
} // end if
} // end for
?>
答案 1 :(得分:-1)
ResponseBody