Codeigniter Pagination Example

This tutorial will show you how to generate pagination using Codeigniter. pagination is recommended when you have lots of data coming from database or external sources and you want to show data which do not fit into a single because it looks ugly and irritating to scroll down the page at bottom.

Read also Effective pagination example in jsf 2  and Create an effective pagination in PHP and MySQL

Pagination Class

CodeIgniter’s Pagination class is very easy to use, and it is 100% customizable, either dynamically or via stored preferences.

If you are not familiar with the term “pagination”, it refers to links that allows you to navigate from page to page, like this:

For more information please read


Netbeans 8.1
XAMPP in Windows
Codeigniter 3.0.6

Configure XAMPP and Netbeans

From Netbeans IDE go to Tools->Options. Click on PHP. Now on tab “General” browse the file for “PHP 5 Interpreter”. The php interpreter file generally placed inside the <physical drive in Windows OS>:xamppphpphp.exe

Configure Codeigniter and Netbeans

Create a new PHP project in Netbeans. Then remove the index.php file from the newly created project. Now copy the extracted files from Codeigniter 3.0.6 to the newly created project directory.

Directory Structure

A typical directory structure for the project would be as shown below. Here assests directory will contain static resources like css, js, images.

codeigniter pagination

Step 1. Now modify <root directory>/application/config/autoload.php file for auto-loading html, url, file, form and session

Step 2. Now modify <root directory>/application/config/config.php file to define encryption key

Step 3. Create a view file under <root directory>/application/views which will be used to display blogs with pagination links at bottom

Step 4. Create a Controller class under <root directory>/application/controllers for handling client’s request and response

Step 5. Create a Model class under <root directory>/application/models for performing database operatins

Step 6. Now modify <root directory>/application/config/routes.php file for pointing the default controller class

Step 7. Now if everything is fine run the application, you will see below output in the browser

codeigniter pagination

codeigniter pagination

Download Database script and assets directory

blogs   assets

Thanks for reading.

Leave a Reply

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