View Single Post
Old 02-19-2009, 11:44 PM   #2 (permalink)
xenon
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

Where are you having problems? To determine how many pages you need, you need 2 variables: the total number of "items" (be it entries in a database or just some records in an array), and the number of "items" you wish to display on a page. The number of resulting pages will be total_number_of_items / number_of_items_per_page. It's just simple math...nothing complicated.

Here's a simple hands-on example:

PHP Code:
$items range(125);
$items_per_page 10;

$number_of_items count($items);
$total_pages ceil($number_of_items $items_per_page); // we use ceil because if we have 11 entries, with 10 entries per page, that means there will be 2 pages

echo $total_pages// this will give 3 
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote