Pagination Class

This is the ultimate pagination class that allows you to easily deliver your content in bite-sized chunks. Go ahead and play around.


The code for the above is written thus:

$page->link('pagination.css'); 
$links = new Pagination (1000); 
$html .= $links->display();

Two excellent resources are at:

object Pagination ( string $query [, integer $display= 10 ] )

This is the constructor for the class, and it creates a pagination object.

$query A MySQL query that returns the total number of records, or if you already know then you can just put the number here.
$display How many records you would like to display at a time.
Example
$links = new Pagination ("SELECT COUNT(*) FROM table");

string limit ( )

This method will return the appropriate ' LIMIT start, display' string for your query to return the desired records.

Returns A string to finish off your MySQL query.
Example
$result = db_query ("SELECT * FROM table" . $links->limit());

string display ( [ integer $split= 5 ] )

This is the paginator method. Put it where you want your links to be displayed.

$split How many links you would like to be on either side of the current page.
Returns A string of code to add to your $html.
Example
$html .= $links->display();

You can download and comment on this class here.

Copyright © 2013 PHP-Ease.com - PHP Made Easy