Re: Pager in Jumping mode

From: Date: Thu, 17 Mar 2005 01:59:48 +0000
Subject: Re: Pager in Jumping mode
References: 1 2 3 4 5  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-18094@lists.php.net to get a copy of this message
Hi Matt, Matt M. wrote:
Do you mean a link to the next set of pages? I.e. it's displaying 1, 2, 3, 4, 5 and you want a link to 6, 7, 8, 9, 10?
yes that is what I want to do. I would like to do my paging like this site does http://digitalgallery.nypl.org/nypldigital/dgkeysearchresult.cfm?keyword=col_id%3A161&so=title
PEAR::Pager doesn't provide what you want to do out-of-the-box, but you can do it this way (please note that I've used the _getLinksUrl() private method to get a clean url, so use it at your own risk...): =============================================== <?php require_once 'Pager/Pager.php'; //create dummy array of data $myData = array(); for ($i=0; $i < 200; $i++) {
    $myData[] = $i;
} $params = array(
    'itemData' => $myData,
); $pager = & Pager::factory($params); $page_data = $pager->getPageData(); $prevPageGroupLink = ''; $nextPageGroupLink = ''; $pageRange = $pager->getPageRangeByPageId(); if ($pageRange[1] < $pager->numPages()) {
    $nextPageGroupUrl  = $pager->_getLinksUrl() . ($pageRange[1] + 1);
    $nextPageGroupLink = '<a href="'.$nextPageGroupUrl.'">&raquo;&raquo;</a>';
} if ($pageRange[0] > 1) {
    $prevPageGroupUrl  = $pager->_getLinksUrl() . ($pageRange[0] - 1);
    $prevPageGroupLink = '<a href="'.$prevPageGroupUrl.'">&laquo;&laquo;</a>';
} $links = $pager->getLinks(); echo $links['first'] . ' &nbsp; ' . $prevPageGroupLink . ' &nbsp; ' . $links['pages'] . ' &nbsp; ' . $nextPageGroupLink . ' &nbsp; ' . $links['last']; ?> =============================================== Alternatively, you can get the whole set of links for the next "group" in this way: =============================================== $nextGroup = ''; $pageRange = $pager->getPageRangeByPageId(); if ($pageRange[1] < $pager->numPages()) {
    $links2 = $pager->getLinks($pageRange[1] + 1);
    $nextGroup = $links2['pages']; //or $links2['all'];
} echo $nextGroup; =============================================== HTH Regards, -- Lorenzo Alberton http://pear.php.net/user/quipo

« previous php.pear.general (#18094) next »