custom pagination help

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
tomsace
Forum Contributor
Posts: 167
Joined: Thu Jan 01, 2009 8:07 pm

custom pagination help

Post by tomsace »

Hey,
I have tried integrating pre-made pagination scripts into my site but all I get is errors because my script has got quite out of hand and is quite long and complicated :)

Anyway I am going to have to make my own, is there a way of using an if statement to use pagination? Heres my thoughts..

Set a variable called something like $resultcount which is set to 0. Each time the loop in the mysql results reaches the end it adds 1 to the $resultcount. Once $resultcount equals 40, the next results are shown on page 2 (In the URL ?page=2 for example so I can link to the next page) and so on etc...

I think this sounds quite reasonable. I have tried this out but... I know the PHP for the if statement and the adding 1 after each loop etc.. but just can't seem to figure out how to set results > 40 to a new page (?page=2 in the URL)?

Any ideas anyone?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: custom pagination help

Post by califdon »

http://www.developerbarn.com/blogs/don9 ... art-1.html
or just search for "pagination" at the top of this page, or in google (add "php").
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: custom pagination help

Post by McInfo »

Retrieving a big chunk of data from the database then using PHP to limit the number of records used is a bad practice. It is better to use COUNT(*) to find the number of records that match your query, then use the LIMIT clause when you actually retrieve the data.

Related topic: 2 Query of LIMIT [int, int] on one page, with 1st int auto c (Pagination example)

Edit: This post was recovered from search engine cache.
Last edited by McInfo on Tue Jun 15, 2010 3:54 pm, edited 1 time in total.
divito
Forum Commoner
Posts: 89
Joined: Sun Feb 22, 2009 7:29 am

Re: custom pagination help

Post by divito »

Post Reply