Home >Backend Development >PHP Tutorial >PEAR Exploration PEAR::Pager_PHP Tutorial
Displaying a large amount of data on a page is a very common practice in WEB projects. However, due to the size of the screen, in order to facilitate user reading, we usually need to display the data in pages, so the paging function is used in most projects. Indispensable. PEAR::Pager is a powerful paging class that is very convenient to use.
System requirements: PHP4.3.*/PHP5, PEAR::Pager
PEAR::Pager has two paging display modes, one is Jumping and the other is Sliding. What is the difference between the two? Let’s look at two examples:
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 "
Current paging mode:".$params['mode'];
echo "
Number of data items displayed per page:".$params['perPage'];
echo "
Display page number:".$params['delta'];
echo "
Specific data array:";
print_r($params['itemData']);
$pager = & Pager::factory($params);
$data = $pager->getPageData();
$links = $pager->getLinks();
echo "
Final effect:";
echo $links['all'];
echo $pager->linkTags;
echo '
Data of the current page: ' ;
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().: ';