Limiting results to first 20 results, then next 20, then...

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

simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Limiting results to first 20 results, then next 20, then...

Post by simonmlewis »

Like so?
1 2
index.php?page=categ&menu=categ&category=Battery Operated Toys&pagenum=2

3
index.php?page=categ&menu=categ&category=Battery Operated Toys&pagenum=3

4
index.php?page=categ&menu=categ&category=Battery Operated Toys&pagenum=4

5
index.php?page=categ&menu=categ&category=Battery Operated Toys&pagenum=5

6
index.php?page=categ&menu=categ&category=Battery Operated Toys&pagenum=6

7
index.php?page=categ&menu=categ&category=Battery Operated Toys&pagenum=7

8
index.php?page=categ&menu=categ&category=Battery Operated Toys&pagenum=8

[Next]
index.php?page=categ&menu=categ&category=Battery Operated Toys&pagenum=2

[Last Page]
index.php?page=categ&menu=categ&category=Battery Operated Toys&pagenum=8
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Raph
Forum Commoner
Posts: 43
Joined: Wed May 27, 2009 6:33 pm

Re: Limiting results to first 20 results, then next 20, then...

Post by Raph »

No, but that was still very useful. Assuming the script is 'sane', the problem lies with the reported amount of pages it should print, and not with the actual printing (since the system looks like it should for a 8-page system).
Read the second half of my previous post. Hopefully there's a problem with $maxPage.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Limiting results to first 20 results, then next 20, then...

Post by simonmlewis »

I rendered the results of numrows and rowsPerPage and this was the result:

Num of Rows: 149
Rows per page: 20

It's wrong though, and it knows it as it only produces about 49 results... not results from 149 rows..??

HOLD ON... i've cracked it....durrr.. :banghead:

This was the error:
$query = "SELECT COUNT(id) AS numrows FROM products WHERE category = '$mycateg' AND stockstatus= 'in stock'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
... on line 79 it didn't do the check on the 'category' field in the table. so it was always producing the numrows for EVERYTHING in the table. Can't believe I didn't spot that, but that's when I just checked the calculations.

It now works perfectly. Just a little CSSing to do on it.

Thank you.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Raph
Forum Commoner
Posts: 43
Joined: Wed May 27, 2009 6:33 pm

Re: Limiting results to first 20 results, then next 20, then...

Post by Raph »

I take it that the pages are error-free now. I'm glad you managed to spot the last step by yourself. Anyone who has the brain to troubleshoot, has the brain to make the troubles in the first place. :mrgreen:
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Limiting results to first 20 results, then next 20, then...

Post by simonmlewis »

[laughs].... very good comment and very true!

It's completely trouble free, so thanks for the 70+ efforts!!!!
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply