I got a problem with a pagination script,
The page is a gallery page with thumbnails that show as soon as the page loads.
There is a limit parameter in the sql, so that only 6 thumbs are presented at a time.
The next and previous links are also working as it's supposed to.
However, when the next get's clicked, it returns the next 6 pictures. I thought everything was fine,
until when I had more than 12 pictures, in my case ,18 pictures. It only shows next results, 2 times!
when I click next the third time, nothing happens! althoug there are still results to show.
Code: Select all
//My class function with sql
//fetch all images
private function fetchAllImages()
{
try{
//pagination script
if(!isset($_GET['startrow']) || !is_numeric($_GET['startrow']))
{
$startrow =0;
}else{
$startrow = (int)$_GET['startrow'];
}
$prev = $startrow - 6;
//only print a "Previous" link if a "Next" was clicked
if ($prev >= 0){
$this->display = true;
}else{
$this->display = false;
}
if("" !=$this->cat){
//run query
$sql = "SELECT * FROM images WHERE category='{$this->cat}'";
}else{
$sql = "SELECT * FROM images ORDER BY category LIMIT $startrow, 6";
}
$result = $this->db->mysqli->query($sql);
//test result
if(!$result)
{ //error handler
throw new Exception("Query failed: " . $sql . " - " . $this->db->mysqli->error);
}else{
//return result from query
return $result;
}
//error handler
} catch(Exception $e){
echo("Message: " . $e->getMessage());
}
}
Code: Select all
// my gallery.php page
....
<?php
//display
$gallery = new Content();
$gallery->PublicDisplayGallery($prev);
?>
...
<?php for($loop = 0; $loop < count($gallery->data);$loop ++) { ?>
<div style="float:left;margin-right: 4px; margin-left: 4px;">
<a href="images/gallery/<?php echo($gallery->data[$loop]['image']);?>" target="_blank"><img alt="" border="2px" width ="150px" height="113px" src="images/gallery/<?php echo($gallery->data[$loop]['image']);?>"></a>
<br>
<span style="font-size:small">description: <?php echo($gallery->data[$loop]['description']);?></span>
<br>
<span style="font-size:small">category: <?php echo($gallery->data[$loop]['category']);?></span>
<br>
</div>
<?php } ?>
<!--PAGINATION NEXT AND PREVIOUS -->
<div align="right">
<table>
<tr>
<?php
//only print a "Previous" link if a "Next" was clicked
$prev = $gallery->prev;
$startrow = $gallery->startrow;
?>
<td><?php if(true == $gallery->Display()){ echo '<a style ="color:red" href="'.$_SERVER['PHP_SELF'].'?startrow='.$prev.'"><< Previous</a>';
}else{echo("");}?></td>
<td> <?php echo'<a style ="color:red" href="'.$_SERVER['PHP_SELF'].'?startrow='.($startrow+6).'">Next >></a>'; ?></td>
</tr>
</table>
</div>
<!--END OF PAGINATION NEXT AND PREVIOUS -->
...
Any help will be greatly appreciated.
Thanks,
Mike Spider