我已經創建了一個很好的下一個和prev圖像鏈接。但我希望他們都回到開始或結束。所以說,我有image101,圖像202和image243,一旦我點擊image243它會回到image101。PHP下一張/上一張圖片Loop
我想同以前的,當我打Image101我想鏈接回去image243。 (自我解釋)。
我怎麼會去這樣做呢?
<?php $sql = "SELECT id FROM albums WHERE user_id=".$user['id']." ORDER BY id ASC LIMIT 1"; $query = mysql_query($sql)or die(mysql_error());
while($album = mysql_fetch_array($query)){ ?>
<?php
$photo_sql = "SELECT photo_id FROM userphotos WHERE photo_id > ".$_GET['pid']." AND photo_ownerid = ".$user['id']." AND album_id=".$album['id']." ORDER BY photo_id ASC LIMIT 1 ";
$photo_query = mysql_query($photo_sql)or die(mysql_error());
$photo_next=mysql_fetch_array($photo_query);
echo "<a href='photo.php?pid=".$photo_next['photo_id']."'>Next</a>";
$photo_sql = "SELECT photo_id FROM userphotos WHERE photo_id < ".$_GET['pid']." AND photo_ownerid = ".$user['id']." AND album_id=".$album['id']." ORDER BY photo_id DESC LIMIT 1 ";
$photo_query = mysql_query($photo_sql)or die(mysql_error());
$photo_prev=mysql_fetch_array($photo_query);
echo " | <a href='photo.php?pid=".$photo_prev['photo_id']."'>Prev</a>";
}
?>
if(mysql_num_rows($ photo_query)== 0){... ORDER BY photo_id LIMIT 1 ...} ... ORDER BY photo_id DESC LIMIT 1 – Waygood 2012-07-12 11:28:33
忘記添加最重要的部分和album_id =「。 $專輯[ '身份證']「。 這可能會或可能不會改變一點點.. – dave 2012-07-12 11:53:28