PHP Pagination Made Easy

This is a PHP pagination class for PHP that can be easily customized however you wish.

Download

Download the PHP pages class for free.

Examples

Example 1

Source

<?php
    $pages 
= new Pages();
    echo 
$pages->getPages(060'#');
?>

Example 2

Source

<?php
    $pages 
= new Pages(50);
    
$pages->firstlink 'First';
    
$pages->prevlink  'Prev';
    
$pages->nextlink  'Next';
    
$pages->lastlink  'Last';
    echo 
$pages->getPages(5005000'#');
?>

Live Demo

The following is a page that makes use of the pages class: bible.search

Methods

Creating the instance

$pages = new Pages([$maxperpage, $maxpagelinks]);

$maxperpage is optional, the default is 30. This is the number of results per page and should coincide with your SQL LIMIT statement

$maxpagelinks is optional, the default is 10. This is the max number of pages to show per page. For example, if there are 50 pages, only 10 will be shown.

Creating the pages

$pages->getPages($startpage, $numberofresults[, $link, debug]);

$startpage is required. This is result number you are on.

$numberofresults is required. This is the number of results returned.

$link is optional, but generally required unless you change $pages->linkformat. This should be the link to the next/previous pages, minus the number. For example, index.php?start=.

$debug is optional, the default is false. A true value will show variables uses within the getPages method..

Optional Parameters

$pages->linkformat, default is <li><a href="#pageslink#">#pagenumber#</a></li>. #pagelinks# is replaced by the link. #pagenumber# is replaced by the page number.

$pages->onpagenumber, default is <li><strong>#pagenumber#</strong></li>. #pagenumber# is replaced by the page number you are currently on.

$pages->seperator, default is LF (\n)

$pages->firstlink, default is ‹ (&lsaquo;)

$pages->prevlink, default is « (&laquo;)

$pages->nextlink, default is › (&rsaquo;)

$pages->lastlink, default is » (&raquo;)