Create Simple Pagination Using PHP and MySQL

Pagination is one of the most frequently used features for web applications. Pagination is the process of dividing a document into discrete pages. Paging allows you to display all of your retrieved results on multiple pages rather than all of them on a single page. So We have shared in this tutorial, we will learn how to Build a pagination PHP & MySQL pagination and enhance it further as per our needs.
Before starting to implement the Simple Pagination Using PHP and MySQL, look files structure:
  • pagination-php-mysql
    • class
      • DBConnection.php
      • Employee.php
    • templates
      • header.php
      • footer.php
    • index.php
Step 1: Create the database and Table
For this tutorial, you need a MySQL database with the following table:
Step 2: Database Connection/Config class
Create a file named DBConnection.php inside “class/” folder.
Step 3: Create a class file
Create a class file named Employee.php inside “class/” folder.
  • The class handles the Employee process.
  • __construct() – Loads the required class.
  • getAllEmployee() – list all recoreds from database
  • countEmployee() – count emp records from database
Step 4: Create HTML file named index.php
Step 5:Create a view(header)
Create a view file named header.php inside “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 “templates” folder.
This view contains the footer section of the webpage.