Hi folks,
I’ve got a strange problem where I’m doing some pagination over items in a catalog, and everything seems to work just fine except when I have exactly one more item than I’m showing per page. Meaning that my second page would end up with exactly one item showing on it.
So in this case the problem occurs when I’m showing a category of products that has exactly 21 items. If it had 22 it would seem to work. I’ve checked out other categories of mine that have a last page with grater than 1 but less than 20 items, and they display just fine.
My SQL appears to be correct, because if I run the statement in the MySQL query browser I do indeed just get one record back. Also, if I dump out the number of rows returned by the query I get (int)20 on the first page and (int)1 on the second page, but on the second page my while loop is not triggered. ?
I think this is really a PHP problem (and not MySQL), but I’m hoping someone here could explain to me just what the heck I’m doing wrong.
Here’s my php code:
[code=php]<?
while($thisRow = mysql_fetch_assoc($qryProductSearch)){
$imagename = $thumbnailpath . ‘/’ . substr($thisRow[‘instylenum’],0,strlen($thisRow[‘instylenum’]) – 4) . ‘.jpg’;
if(!file_exists($imagename)){
$imagename = $thumbnailpath . ‘/noimage.jpg’;
}
?>
<div class=”ListItem”>
<table border=0>
<tr>
<td style=”text-align: center;”>
<a href=”products.php?s=<? echo urlencode($thisRow[‘instylenum’]);?>”>
<img src=”<? echo $imagename; ?>” style=”width:100px; height:100px; border:1px solid gray;”>
</a>
</td>
</tr>
<tr>
<td style=”text-align: center;”>
<span class=”redtext bold”><a href=”products.php?s=<? echo urlencode($thisRow[‘instylenum’]);?>” style=”font-size:11px;”><? echo $thisRow[‘instylenum’]; ?></a></span><br>
</td>
</tr>
</table>
</div>
<?}?>
</div>
The above while loop just doesn’t seem to want to work when there’s only one row in the data. I’m not sure what I can do. ?
Any help would be greatly appreciated.
Thanks,
Chris