可能重复:
Previous/next Buttons?
如何在我的图库脚本中制作下一页和上一页.. 当
mid = id of images
path = link of images
我需要两个按钮: next 以获取下一张图片, prev 以获取最后一张图片。我该怎么办?
$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 } ?>
答案 0 :(得分:0)
如果您正在使用$_GET
,我认为这将是一个动态页面,您可以查看照片,您想要显示下一张照片,而不是在页面上显示,如果是这样,请尝试使用此< / p>
<?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>