Pagination Using CodeIgniter and MySQL

Pagination, also known as paging, is the process of dividing a document into discrete pages.Pagination allows us to break down our results into small manageable parts. In this tutorial I am going to explain how to create pagination or feature using Pagination Using CodeIgniter and MySQL. This is a very simple example, you can just copy paste and change according to your requirement.
Before started to implement the Pagination Using CodeIgniter and MySQL look files structure:
  • pagination-using-codeIgniter-mysql
    • application
      • config
        • autoload.php
        • database.php
        • constants.php
        • pagination.php
        • routes.php
      • models
        • News_model.php
      • controllers
        • News.php
      • views
        • news
          • index.php
        • templates
          • header.php
          • footer.php
    • system
    • index.php
    • assets
      • css
        • style.css
Step 1: Create the database and Table
Run the following script against MySQL to create the database news table.
Step 2: Initialization CodeIgniter pagination library
Initialization CodeIgniter pagination library (file name: pagination.php) “application/config/” folder.
Step 3: Create Model
Need a model file News_model.php inside “application/models” folder, that fetches records from the news table
Step 4: Create a controller file
Create a controller file named News.php inside “application/controllers” folder.
  • The Contact controller handles the contact form process.
  • __construct() – Loads the required library, helper.
  • index() – fetch data.
Step 5: Create a view(header)
Create a view file named header.php inside “application/views/templates” folder
This view contains the header section of the webpage. The Bootstrap library is used to provide a better UI, so, include it in the header section.
Step 6: Create a view(footer)
Create a view file named footer.php inside “application/views/templates” folder
This view contains the footer section of the webpage.
Step 7: Create a view(index)
Create a view file named index.php inside “application/views/news” folder