Home > php教程 > php手册 > PEAR探奇之PEAR::Pager

PEAR探奇之PEAR::Pager

WBOY
Release: 2016-06-13 09:58:27
Original
1490 people have browsed it

  在页面上显示大量数据,是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 "
Copy after login
";

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().: ';

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template