Pagination in PHP

Pagination is the process to split huge number of records in order to create dynamic pages. By using PHP we can easily setup a pagination script to display record from database. Pagination is mainly used in search result and displaying the table of content like name and address.

Pagination in PHP
Click image to view Larger
So in this example I will explain you how to setup a simple CSS styled PHP pagination script.

Above image will explain you how pagination will work? You can view demo or download the example file below and custimize to your requirement and layout.

Download FileDemo

Create a table in database

CREATE TABLE `articles` (
`title` VARCHAR( 256 ) NOT NULL ,
`description` MEDIUMTEXT NOT NULL ,
`link` VARCHAR( 256 ) NOT NULL

Copy and paste below code in index.php

$page = (int) (!isset($_GET["page"]) ? 1 : $_GET["page"]);
$page = ($page == 0 ? 1 : $page);
$perpage = 8;//limit in each page
$startpoint = ($page * $perpage) - $perpage;

After this make sure that you have included the Pagination.php in your index.php file.

We can use this type of pagination simply to display records from database. If you want to make pagination for search result we have to go for PHP Ajax Pagination System. I will explain this type of pagination system later.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>