Possible Duplicate:
Previous/next Buttons?
how can i make next page and prev page in my gallery script .. when
mid = id of images
path = link of images
I need two buttons: next to get next image and prev to get last image. How can i do it ?
$mid=$_GET['mid'];
$qur="select * from images where mid='$mid'";
$res=mysql_query($qur,$conn);
?>
<?php while($row=mysql_fetch_array($res)){ ?>
<div class="gallery-img">
<a href="admin/<?php echo $row['path'] ?>" rel="prettyPhoto" class="portfolio-img" title="<?php echo $row['image_title'] ?>">
<img src="admin/<?php echo $row['path'] ?>" alt="<?php echo $row['image_title'] ?>" width="100%" height="100%" />
</a>
</div>
<?php } ?>
If you're using $_GET
I'm assuming this would be a dynamic page you go to to view a photo, which you want to show next and prev than on the page, if so than try this
<?php
$mid=mysql_real_escape_string($_GET['mid']);
$res=mysql_query("select * from images where mid='".$mid."'",$conn);
$prevSQL = mysql_query("SELECT mid, path FROM images WHERE mid > '".$mid."' LIMIT 1");
$nextSQL = mysql_query("SELECT mid, path FROM images WHERE mid < '".$mid."' LIMIT 1");
$row = mysql_fetch_assoc($res);
if(mysql_num_rows($prevSQL)>1){
$prevRow = mysql_fetch_assoc($prevSQL);
$prev = '<a href="admin/'.$prevRow['mid'].'">Prev</a>';
} else {
$prev = 'Prev';
}
if(mysql_num_rows($nextSQL)>1){
$nextRow = mysql_fetch_assoc($nextSQL);
$next = '<a href="admin/'.$prevRow['mid'].'">Next</a>';
} else {
$next = 'Prev';
}
?>
<div class="gallery-img">
<a href="admin/<?=$row['path'] ?>" rel="prettyPhoto" class="portfolio-img" title="<?=$row['image_title'] ?>">
<img src="admin/<?=$row['path'] ?>" alt="<?=$row['image_title'] ?>" width="100%" height="100%" />
</a>
<?=$prev.' '.$next;?>
</div>