SQL PHP HTML ASP JavaScript articles and free scripts to download
 

PHP Paging: Breaking records into different pages

If there are more records in a table ( say more than 50) then it will not look nice to display all the records in one page and asking 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) .We have to give navigational link at left and right side saying previous and next page. We also have to give links at the center so the visitor can visit in between pages of his/her choice.

The below 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.

Now Check our new code: Ajax based Paging script using PHP & MySQL

We can expect our navigational menu at bottom of the page to look like this.


 Name Class Mark
 Babby John Four 69
 Reggid Seven 55
 Herod Eight 79
 Tiddy Now Seven 78
 Giff Tow Seven 88
 Crelea Seven 79
 Big Nose Three 81
 Rojj Base Seven 86
 Tess Played Seven 55
 Reppy Red Six 79
PREV   1  2  3  4 NEXT
    Before going into details of how to write the code, please visit php mysql connection page to check that you have connected to mysql db. 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.   

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 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.    

PHP paging Part II >>

Customizing the paging script with user selection of number or records per page >>

Sorting data by column header in paging script Part III >>

PHP paging demo I >>

Selection of number of records per page in PHP paging demo II >>

Column header sorting demo III >>

Download the ZIP file here  php_paging.php



Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked


Join Our Email List
Email:  
For Email Newsletters you can trust
PHP Paging
PHP Sections