PHP Pagination Simple Mechanics
It is actually very simple. All you need to know is what page you are on and how many items there is to list in total. Here is an out line:
Step one, get those values:
total_items
items_per_page
current_page
Step two, calculate total pages:
total_pages = ( total_items / items_per_page )
Step three, calculate limit offset for database query:
start_item = current_page * items_per_page
end_item = if on last page then ( total_pages – start_item ) else ( items_per_page ) “asuming your database works like mysql”
Be mindful that arrays and databases start from 0 not from 1.
And from there just make your PHP code and add on nifty features of your own.
Check out my previous guide for a nice pagination script with demo.