-3

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 } ?>
Jonas
  • 121,568
  • 97
  • 310
  • 388
ahmedhassan
  • 23
  • 3
  • 12

1 Answers1

0

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>  
Ken Keenan
  • 9,818
  • 5
  • 32
  • 49
Bobby
  • 4,332
  • 5
  • 32
  • 39
  • 4
    please, do not feed [help vampires](http://www.slash7.com/pages/vampires) – tereško Jun 10 '12 at 19:05
  • @Bobby Thanks For Your Feedback But i Have Question .. How can i make =$prev.' '.$next;?> In link ?? – ahmedhassan Jun 10 '12 at 19:43
  • @afrogfx as shown in the above code, `$next` and `$prev` are all ready defined, so when you call `=$prev.' '.$next;?>`, you are calling on the links all ready created by the script. And if there is no next or prev it will just create the text with no link. – Bobby Jun 10 '12 at 19:45
  • @Bobby Thx Angie ... But I Want preview This code in HTML ?? i don't know how can i make next in link and perv in link ? =$prev.' '.$next;?> becouse when this code show ?? show without link just show Prev Prev – ahmedhassan Jun 10 '12 at 19:53
  • @Bobby I need my link Like It ?? but in html ? how can i make it =$prev.' '.$next;?> Like It ? Prev Next – ahmedhassan Jun 10 '12 at 20:53