PHP Classes
elePHPant
Icontem

File: class.pager.example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of spajus  >  Page Magic  >  class.pager.example.php  >  Download  
File: class.pager.example.php
Role: Example script
Content type: text/plain
Description: The example
Class: Page Magic
Generate pagination HTML links with text templates
Author: By
Last change:
Date: 10 years ago
Size: 2,417 bytes
 

Contents

Class file image Download
<?
   
   
//pager example
   
   
include('class.pager.php');

   
$total = 128; //this value should arrive from some database query, like "select count(id) from table_you_want_to_page"
   
$perpage = 15; //number of results to be shown per page
   
$query_string = "class.pager.example.php?"; // current file..
   
   
$pager = new pager($total, $perpage, $query_string); //building a pager

   
echo "Pager example: Dividing {$pager->num_results} results into {$pager->page_list_size} pages showing {$pager->per_page} results per page<br><br>";
   
   
$pg = $pager->page; //getting active page
   
   
echo "<br>Active page " . $pg;
   
    echo
"<br><br> Page list: ";
    echo
$pager->getButPrev($pg); // get PREVIOUS button
   
if($pager->getButPrev($pg)) echo $pager->separator; //show a default seperator between PREVIOUS button and page list IF previous button is visible
   
$range = 4; //set the range of page button list
   
echo $pager->getButList($range); //display page buttons.. 1 2 3 4 5 etc
   
if($pager->getButNext($pg)) echo $pager->separator; //show a default seperator between page list and NEXT button IF next button is visible
   
echo $pager->getButNext($pg); //get NEXT button
   
echo "<br>";
   
    echo
$pager->getRangeInfo(); // print "showing results x - y of z"

    //some design tuning!
   
$pager->but_prev = "<a href=\"{query_string}&page={page}\"><strong>&lt;&lt; ({page})</strong></a>";
   
$pager->but_next = "<a href=\"{query_string}&page={page}\"><strong>({page}) &gt;&gt;</strong></a>";
   
$pager->but_page = "<a href=\"{query_string}&page={page}\">[Page: {page}]</a>";
   
$pager->but_page_this = "[Active page: {page}]";
   
$pager->separator = ".";
   
$pager->range_display = "You see results: {from} to {to} out of {total}";

   
//now redraw..
   
echo "<br><br> Retuned Page list: ";
    echo
$pager->getButPrev($pg);
    if(
$pager->getButPrev($pg)) echo $pager->separator;
    echo
$pager->getButList(6);
    if(
$pager->getButNext($pg)) echo $pager->separator;
    echo
$pager->getButNext($pg);
    echo
"<br>";
    echo
$pager->getRangeInfo();
   


    echo
"<br><br>Extra info:<br><br>";
   
    for(
$i = 1; $i <= $pager->page_list_size; $i++){
        echo
"Page " . $i;
        echo
" -> Offset in db query: ";
        echo
$pager->getPageFrom($i);
        echo
"<br>";
    }
   
   
//so, if you are in page 4, you should request results in database limited from $pager->getPageFrom(4), and running for $pager->page_size in length..
    
   
?>