tags:

views:

39

answers:

2

Hi,

I am working on a paging function. This is what I have:

$total_pages = 3; // 3 is only an example

foreach ($total_pages as $single_page):
echo 'Page'.$single_site->number.'|';
endforeach;

How can I write the number of pages in array that I can use in my foreach function?

The number of pages is dynamical. I want to be able, to show a value for each page like: Page1, Page2 and so on. Dependening on the number of total pages.

+1  A: 

You can use range():

foreach (range(0, $total_pages - 1) as $single_page)

but even easier is to just use a normal for loop:

for($i = 0; $i < $total_pages; $i++)
Felix Kling
A: 

Zend Paginator is a great way to paginate data, and makes it relatively easy to implement a scrolling pagination control (showing only a subset of pages numbers relative to the current page number). If your application has a lot of pages of results, then showing a scrolling pagination control will provide a better user experience than showing hundreds of "Page X" links in succession.

A sliding control might look like: [Prev] 1 ... 4 5 6 7 8 ... 200 [Next]

Michael