For Programmers: Free Programming Magazines  


Home > Archive > PHP Pear > March 2005 > Re: [PEAR] Pager in Jumping mode









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [PEAR] Pager in Jumping mode
Matt M.

2005-03-16, 3:59 pm

> 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 don't see the point of such a thing. Why would you need yet another

set of links for
> this? Perhaps you want to try the Sliding pager?


I would like to do my paging like this site does
http://digitalgallery.nypl.org/nypl...%3A161&so=title
Lorenzo Alberton

2005-03-17, 3:56 am

Hi Matt,


Matt M. wrote:
>
> yes that is what I want to do.
>
> I would like to do my paging like this site does
> http://digitalgallery.nypl.org/nypl...%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.'">»»</a>';
}
if ($pageRange[0] > 1) {
$prevPageGroupUrl = $pager->_getLinksUrl() . ($pageRange[0] - 1);
$prevPageGroupLink = '<a
href="'.$prevPageGroupUrl.'">««</a>';
}

$links = $pager->getLinks();

echo $links['first']
. '   '
. $prevPageGroupLink
. '   '
. $links['pages']
. '   '
. $nextPageGroupLink
. '   '
. $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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com