PHP Paging: Breaking records into different pagesIf there are more records in a table ( say more than 100) then it will not look nice to display all the records in one page and ask the visitors to scroll down to see all the records. This will also slow the process of loading of records. So it is better to break all the collected records into different pages with a fix number of records per page ( say ten records per page) .
Out of say 100 records we will display first 1 to 10 records and then give a link at the end to display next 10 records. On click of this link we will display 11 to 20 records. At the same time the user may like to return to first 1 to 10 pages so we will be displaying another link saying Previous. So we can move forward or backward to navigate between pages.
We can also display links for all the ten pages so user can directly go from 2nd page to 7th page.
Now Check our new code: Ajax based Paging script using PHP & MySQL
Here is an example of records displayed using Paging functions
We will be using several SQL functions to manage records. Ensure that you have Mysql PDO connection to database.
Also read the article on how to display data from MySQL table here. We will be
using some sql commands like sql limit, order by etc so you can refer them in
our sql section.
| Name|| Class|| Mark|
| Babby John|| Four|| 69|
| Giff Tow|| Seven|| 88|
| Crelea|| Seven|| 79|
| Big Nose|| Three|| 81|
| Reppy Red|| Six|| 79|
Now let us have one table with nearly 35 records. We will
use the student table for this and you can use code sample at the end of this
tutorial to download the MySQL dump file to create the table along with the
Advance Php paging script
The above menu is further improved if you have more records. For more than 1000 records and if you have 10 records per page then you have to show 100 links at the bottom of the page. That can be further simplified in advanced script to make links in groups. Click here to download the code and check the demo of advanced php paging. But it is better to understand the basic script first.
|Paging Script||Php script part of basic paging script ( part II)|
|user choice||User can select number of records per page by selecting drop down list|
|Header control||Change the listing order by clicking the column header|
|Advance Paging||Advance paging script with outer and inner paging|
|Ajax Paging||Paging without reloading page by using Ajax|
|Delet Record||Ajax paging with record delete option|
Demo : Examples using PHP paging script
|Demo|| Example Description|
|Basic Paging||Demo of basic paging script|
|User Selection||Demo of user selection of number of records per page|
|Header Link||Sorting of paging records order by different column headers|
|Advance Paging||Inner and outer links for paging of records in advance paging script|
Demo of Basic Paging script
PHP paging Part II
Download the ZIP file here php_paging.php