Paging function/navigation (running through an array)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
visionmaster
Forum Contributor
Posts: 139
Joined: Wed Jul 14, 2004 4:06 am

Paging function/navigation (running through an array)

Post by visionmaster »

Hello together,

At the moment (actually the whole day) I'm having problems impementing a paging fuction. For most of you this problem may be trivial to you, but I really can't get it to work to my satisfaction. I guess I'm thinking way to complicated... :-(

I'm doing a search and save alle found results in a session-array. So I run through a array. Now I would like to provide a paging function (navigation). Only 10 pages at a time should be displayed in my paging navigation. Of course a search query may give back less than 10 results.

Furthermore the user is able to choose how man results should be displayed pro page, 10 results, 20 results or 30 results:

[1] 2 3 4 5 6 7 8 9 10 >> next

A click on >> next goes to page 2:

<< previous 1 [2] 3 4 5 6 7 8 9 10 >> next

So >> next goes to the next page forward
So << back goes to the previous page back


Now suppose I'm on page 10 an click >> next

<< previous 1 2 3 4 5 6 7 8 9 [10] >> next

Since I just want to display a maximum of 10 pages in my navigation, the pages should shift 1 to the right, like this:

<< previous 2 3 4 5 6 7 8 9 11 [12] >> next

(Particularly the shifting function is giving me a headache...)

Another click on >> next :

<< previous 3 4 5 6 7 8 9 11 12 [13] >> next

(Previous should work the same, just backwards.)

Last but not least, one should be able to directly click on a number.

Thanks for your patience and help!
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Please do a search on pagination first, then let us know if that didn't help you out. One of the most common questions that have been discussed very often.
Post Reply