Pagination Class. PHP

vicnumb May 14, 2013

May 14 2013 Published by under PHP & MySQL

Pagination is frequently used on displaying large lists that are too big to be displayed on a single page.

As a solution of displaying large lists is

  • Splitting the list into small portions.
  • Displaying one list portion per page.
  • Setting up a menu with possibility to navigate between pages.

Pagination menu coding is a time consuming job.

On my own experience, simplest method is to keep tracking of pagination menu separately and pull out data from source separately. Data are pulled out of data source using the pagination variable – page ID. Page ID point to the current page, therefore to a specific dump of data.


Pagination Class Goals

  • send the current page variable (page ID) from page to page, when clicking the navigation menu;
  • display pages by small blocks of 5-10 pages links (if we have 1000 pages and display links to them at once, it’s going to be a total mess);
  • have a simple navigation between blocks and a links to first and last pages;
  • current page is not linked;


Pagination Class visible example:

– There is a list of 267 items to be displayed.
– Display by 10 items per page.
– Total pages number is 27.
– Current page is 17.
– Pages are displayed by blocks of 5 at a time.

a) Navigation menu:
<< < 16 17 18 19 20 > >>

b) On clicking the left single arrow (base item a) we get the following:
<< < 11 12 13 14 15 > >>

c) On clicking the right single arrow (base item a) we get the following:
<< < 21 22 23 24 25 > >>

d) On clicking the left double arrow (base item a) we get the following:
1 2 3 4 5 > >>

e) On clicking the right double arrow (base item a) we get the following:
<< < 26 Pagination class is totally separated from data storage/pull out and displaying.
The only marker is the current page variable. Acodring to this variable we pull out data from our storage.


Pagination Class example of use:

This generic example shows how to build pagination menu.

$pag = new Pagination;
$pag->valcount =999; //Number of items in the list (int)
$pag->curpage = 7; //current page ID (int)
$navbar = $pag->pagebar();
echo $navbar;


Pagination Class more details:

No responses yet

Leave a Reply