2012-11-28 50 views
1

我想知道是否有人可以幫我解決一些分頁問題。使用pajinate,我最初把它放在一起,但它似乎被竊聽。我想添加「上一頁」和「回頁首」以及「下一頁」和「最後一頁」按鈕。我試着先執行'回到開始'和'上一個'按鈕,但他們不能正常工作。如果有人能夠幫助我一點,那就太棒了。在附註中,我設置了一次顯示10個數字的範圍,但每次點擊更高的頁碼時,它都會附加4-5個數字,對此問題的任何見解都將不勝感激。eBay購物API分頁

<?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&currentpage=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 
?> 

回答

1

你曾上一頁註釋掉,並使用$ _GET [ '當前第']而不是$ _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 
?> 
+0

更明確:我將<更改爲< JohnnyFaldo

+0

這對我有用。重新調整總頁數。有更多的頁面,但我只想要一次顯示10個數字,當你選擇另一個頁面通知時,它會附加更多。我的下一個問題是獲取下一個和最後一個按鈕。 http://valueguide.pga.com/file-exec/f/ebaystore/h/true – MDez

+0

唯一的問題,當我選擇它恢復到一般的結果,而不是對當前過濾的結果your're另一頁。 – MDez

-1
$offset = ($currentpage - 1) * $entriesPerPage; 


if ($currentpage > 1) { 

?where comes this variable 
+0

這不是一個答案,它甚至不認爲它可能是一個好評。 StackOverflow問題(和答案)並不意味着成爲討論事物的媒介。你要麼知道答案,要麼你不知道。如果您想要詢問用戶,請考慮發佈對問題的直接評論。另外,請查看StackOverflow幫助部分。 – Overflowh