<?php /** * Basic pager example */ require_once 'package.oLimit.php';
/** * How many items are to be displayed on the page * */ DEFINE ('PER_PAGE', 20); /** * Defining the array to be displayed */ $aTab = range (1, 638, 5); /** * Counting how many pages will be needed */ $iNbPages = ceil (count ($aTab)/PER_PAGE); /** * checking and overwriting if necessary the GET variable (page number p) */ if (!isset ($_GET['p']) || !is_numeric ($_GET['p']) || $_GET['p'] < 0 || $_GET['p'] >= $iNbPages) { $_GET['p'] = 0; } /** * Displaying the pager */ $sHtml = '<div>'; for ($i = 0; $i < $iNbPages; $i ++) { $iDisplay = $i + 1; $sColor=(isset($_GET['p']) && (int)$_GET['p'] === $i)?'background-color: rgb(195,195,195);':''; $sHtml .= <<<HTML <span style="border: 1px solid rgb(0,0,0); padding: 3px; {$sColor}"><a href="limit.pager.php?p={$i}">{$iDisplay}</a></span> HTML; } $sHtml .= '</div><br /><br />'; /** * Determining starting offset from current page number */ $iOffset = (int)$_GET['p'] * PER_PAGE; echo $sHtml;
try { /** * Creating the arrayLimit object, using the factory, and determined values (starting offset, items to be displayed on a page) */ $limit = LimitFactory::factory ('ARRAY', $aTab, $iOffset, PER_PAGE); while (true === $limit -> valid()) { echo $limit -> key (), ' => ', $limit -> current (), '<br />'; $limit -> next (); } } catch (Exception $e) { echo $e -> getMessage (), ' on line ', $e -> getLine (); } ?>
|