A PHP pagination component
PHP
Latest commit 47c2440 Jan 21, 2010 @jimmiw all variables are now camal cased. Moved the "total count" in the con…
…structor. Added ways to set the next and previous texts.
Permalink
Failed to load latest commit information.
lib all variables are now camal cased. Moved the "total count" in the con… Jan 21, 2010
README.textile

README.textile

Paginate a Pagination component for PHP

This component has two files.
Paginate.inc.php
It is used in the controller (if speaking MVC terms) and sets up some
convinience methods for you to use.

PaginateViewHelper.inc.php
It is used to render a pagination bar.

NOTE: this component currently relies on MySQL, so remember to set up your
connections before using it in your code!

You have to tell the component what page we are currently on and what table
your data is to be taken from. This is “all” you need to do.

Example

For simplisity, i’ll just use a single file called index.php

<?php

// make your connection to the database

// initializes the pagination lib
$paginate = new Paginate(
“posts”, // the table name in your database to find ALL items from
$current_page, // the current page
$items_per_page // number of items per page
);

// use the paginate view helper to make the pagination bar
$paginateViewHelper = new PaginateViewHelper(
$paginate→getCurrentPage(), // the current page we are on, e.g. 1
$paginate→getItemsPerPage(), // number of items per page, e.g. 5
“/blog/page/” // the link to have before the page number
);

// renders the pagination bar. Only needs to know to total amount of pages
// this can be taken from the $paginate object.
echo $paginateViewHelper→render($paginate→getTotalPages());

?>