PHP Classes
Icontem

File: limit/limit.pager.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Johan Barbier  >  SPL and Iterators  >  limit/limit.pager.php  
File: limit/limit.pager.php
Role: Example script
Content type: text/plain
Description: Example on how to build a pager with oLimit package
Class: SPL and Iterators
Implements several iterators using SPL
 

Contents

Class file image Download
<?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 (16385);
/**
 * 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'] < || $_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$iOffsetPER_PAGE);
    while (
true === $limit -> valid()) {
        echo 
$limit -> key (), ' => '$limit -> current (), '<br />';
        
$limit -> next ();
    }
catch (Exception $e) {
    echo 
$e -> getMessage (), ' on line '$e -> getLine ();
}
?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products