Spread the love

Hello, Friends!

Do you want to create pagination in php with next and previous buttons?

Mostly we have a large amount of data in the database. If we want to display that data on the web page. for that, we use SQL SELECT Query and  This query actually fetch all the record from the database table. So obviously it is not a good experience to display all the record on one single page because it will take too much time to load. So, for this reason, we using pagination to split all the record into multiple pages.

What is pagination?

 Paging or Pagination is simply mean to organize all the selected data on more than one page to make them more user-friendly and to make them less time-consuming.

How to create pagination in PHP and MYSQL

To create pagination in php is a really simple task. For this, we just use MYSQL’s LIMIT clause which uses two arguments one is the offset and the second one is the number of records which we want to fetch from the database.

So to create php pagination script use the following simple steps.

1.Code for the current page:


2. First of all, create pagination logic in php:


3. Write MySQL query for pagination:

In the following query, we use the LIMIT clause use to specify the number of records to be fetched.


4.Select the total record from the database:


5. The PHP script for the previous button:


6.PHP logic for the middle pages, between previous and next 

In the following script ceil function as a function used to make round off the number to the nearest integer. for example ceil(3.8)=6


7.The script for the next button:


Now combine all the above code:



In the above tutorial, we displayed the record on a simple table we have been fetched a student record from a database name is  “ student” and display all the record on simple HTML page each page contain 10 records.

Ps: if you find this article helpful then like and share with your friends.