Closed Thread Icon

Topic awaiting preservation: pagination with PHP/MySQL (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12405" title="Pages that link to Topic awaiting preservation: pagination with PHP/MySQL (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: pagination with PHP/MySQL <span class="small">(Page 1 of 1)</span>\

 
Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 09-06-2002 01:50

I'm trying to paginate the results of a db query. I've got everything working fine except one part.

Let's say I limit the results to 20 rows per page. At the bottom of the page, a button says "Next 20", which takes me to the next page of results (duh!). On that page, I now have a button that says "Next 20" as well as "Previous 20" to go back.

This works fine EXCEPT on the first time. If I go to the second page of results, and the 'previous' button says "Previous 19" instead of "Previous 20". Sure enough, it only shows the previous 19 results, leaving off the last one. It gets more interesting in that if I keep going back in forth between NEXT and PREVIOUS, that number drops 1 each time.

I belive it's because of the way I'm calculating things, but I'm a little unsure how to proceed. If I just keep going forward through the results, everything works fine. And I can keep going back in the results without a problem, until I get to the very first page of results.

I'm pretty sure this is a "0" vs "1" thing.

I could sure use a pair of eyes....
http://dev.runningwolf.com/code/php/vcf_db/guns/list.php for the working page, and http://dev.runningwolf.com/code/php/vcf_db/guns/list.phps for the source.



[This message has been edited by Pugzly (edited 09-06-2002).]

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 09-06-2002 03:38

Pugzly

I think the problem may be in this part of the code:

$presql = "select uid from users where uid < $start order by uid desc";

If $start == 20 and you SELECT everything < 20 it will return 19 rows from the database because the first row is 1 and not 0.



-Butcher-

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 09-06-2002 03:57

I was wondering if the problem was related to the first row being 1 and not 0. Guess it is then.

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 09-06-2002 04:07

Hmmm...that's kinda my thinking, too. But I'm kinda lost as to what to do about it.





[This message has been edited by Pugzly (edited 09-06-2002).]

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 09-06-2002 18:14

hmmm... thinking, thinking.

What happens if you change your sql to <= $start ??

IF I'm reading this correctly the only thing that sql is for is for in exactly this spot, so that if for some reason there are less than $l records left you put the correct number on the button. Which means that the only time this part

}else if($prerow < $l){
$pre = $prerow;
}

will evaluate true is one page from the beginning.



.:[ Never resist a perfect moment ]:.

« BackwardsOnwards »

Show Forum Drop Down Menu