Wednesday, 11 July 2018

PHP: Simple Pagination

This article shows how to create a simple pagination in PHP and MySQL.
In the example code present in this article:
– We will be fetching data from a MySQL database table.
– We will be showing certain rows of data in first page and other rows will be displayed in next pages.
– We will show the page numbers at the bottom of the page.
Let’s suppose our database is test. Let’s create a MySQL database table named users inside database test.
Let’s add/insert some data in table users
Here are the steps to be followed in the PHP code:
1. Connect to the MySQL database table
2. Set a row limit for each page, i.e. number of rows to show on each page
3. Identify page number and offset
4. Count the total number of rows in database table
5. Determine the total number of pages to be displayed
6. Fetch row data from database table using the offset and limit as determined in step 2 and 3 above.
7. Display/Show data
8. Display/Show page numbers using number of pages as determined in step 5 above.
Here’s the full source code:

0 comments:

Post a Comment