Page 1 of 1

custom pagination help

Posted: Tue May 05, 2009 4:30 pm
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?

Re: custom pagination help

Posted: Tue May 05, 2009 5:33 pm
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").

Re: custom pagination help

Posted: Tue May 05, 2009 11:51 pm
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.

Re: custom pagination help

Posted: Thu May 07, 2009 11:37 am
by divito