How to do Paging?
Author : Sumit Gupta
In every programmers life he need to do paging to display the Next, Previous Button with all the pages number while doing reporting, I have come across this may times. All I need to show is display 10 /20 records per page and when user clicks the "Next Button" take him to next page to display Next set of records. So I write this simple Function for the same, It simply Count the Total records and Display the Previous, Next button and Create a list of pages with there "page Number".
Function for the same is given below:
Main Pagin Function
How does it works?
It Need some tweaking before it can be used. Replace the and with the relevant data and than simply call it in your print or Echo statement.
Like
echo shownavigation()
Than in you page at top add these lines
What will this function do ?
It first count the no of records from the Database record, this query must be same as the Final data fetching query in where clause and table selection, than it count how many pages will be created from these count depending on your records count.
After doing that it simply Check for which buttons to show in navigations. i.e from the list of previous, Page number and Next button.
Believe me this function will help you a lot as just you need to copy paste the function and change few thing and the paging is ready to use. Though there are some tweaks still remains in this function but that I will tell you next time.