Skip to main content

How To Use Pagination in Codeigniter

Pagination is a most important feature of any web application, it is useful when we have to show the large set of record. Pagination provides functionality, to load limited record in the single page, it will help to load application much faster and decrease page load time.

Codeigniter provides built-in pagination library and it will be easily configurable. So we can easily integrate the pagination functionality in our web application.

Benefits of Using Pagination

1) Better User Experience
2) Handle large set of record
3) Decrease page load time

Tutorial summary is:-

  • Create MySQL table and insert a record in it for demo purpose
  • Create controller, view, model file and load pagination library
  • Fetch Record from a table and pass it to the pagination function
  • Show the pagination links in the view file

So now we move to the coding parts and we follow step by step tutorials

EmployeeController.php :-

Employee controller class fetch the record from the database and handle all the pagination related request. It contains two methods

function __construct() :-

  • Load Pagination Library
  • Load Employee Model
  • Load Url Helper and database configuration

function employeeList() :-

  • Define Pagination configuration
  • Fetch Data From employee_details table
  • Paginate the Data
  • Pass Data To the View File

EmployeeModel.php :-

Employee model class handle all the database related request,Fetch data from table,setup pagination links and configurations.It contains two methods
function getEmpData

  • Fetch data from table according to pass offset and limit
  • Count Total Records

function pagination

  • Create Pagination link like previous,next,page counts
  • Show pagination message like per page


employee list.php view file show the record and pagination

Conclusion:- Today we have learnt about how to easily integrate pagination in Codeigniter

I hope this tutorial helpful for you, Please share this post in social media



Recomended Tutorial

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.