在页面上显示大量数据,是WEB项目中很常见的一个作法,但限于屏幕的大小,为了便于用户阅读,我们通常需要将数据分页显示,所以分页功能是大部份项目不可缺少的。PEAR::Pager是一个功能强大的分页类,使用非常方便。
系统需求:PHP4.3.* /PHP5,PEAR::Pager
PEAR::Pager有两种分页显示模式,一是Jumping,二是Sliding。两者有什么区别,我们来看两个例子:
Jumping.php
require_once 'Pager/Pager.php';
$params = array(
'mode' => 'Jumping',
'perPage' => 3,
'delta' => 5,
'itemData' => array('a','b','c','d','e','z','ty','xc','fg','fg','jk','hj','ty','xc','e','z','ty','xc','fg','fg','jk','hj','ty','xc')
);
echo "
当前分页模式:".$params['mode'];
echo "
每页显示数据条数:".$params['perPage'];
echo "
显示页数:".$params['delta'];
echo "
具体数据数组:";
print_r($params['itemData']);
$pager = & Pager::factory($params);
$data = $pager->getPageData();
$links = $pager->getLinks();
echo "
最后效果:";
echo $links['all'];
echo $pager->linkTags;
echo '
当前页的数据: ' ;
echo "
";<br> print_r($data);<br> echo "";
";
echo 'getCurrentPageID()...: ';
var_dump($pager->getCurrentPageID());
echo "
";
echo 'getNextPageID()......: ';
var_dump($pager->getNextPageID());
echo "
";
echo 'getPreviousPageID()..: ';
var_dump($pager->getPreviousPageID());
echo "
";
echo 'numItems()...........: ';
var_dump($pager->numItems());
echo "
";
echo 'numPages()...........: ';
var_dump($pager->numPages());
echo "
";
echo 'isFirstPage()........: ';
var_dump($pager->isFirstPage());
echo "
";
echo 'isLastPage().........: ';
var_dump($pager->isLastPage());
echo "
";
echo 'isLastPageComplete().: ';