我正在使用此脚本在图片之间移动:
$photo_sql = "SELECT * FROM images WHERE image_folder_id = $folder_id ORDER BY image_id ASC";
$photo_result = mysql_query($photo_sql) or die(mysql_error());
while ($row = mysql_fetch_array($photo_result)) {
$photos[] = $row[0];
}
$total = mysql_num_rows($photo_result);
// Testing example:
// $photos = array(200, 202, 206, 211);
// $total = count($photos);
$current = $_GET['image_id']; // whatever your position is in the photo array
if ($current > ($total-1) || $current < 0) {
echo "Error: nonexistent photo ID.";
exit;
}
echo '<img src="images/'.$photos[$current].'.png" alt="my image!" />'; // display current photo
$next = ($current+1) % $total; // modulo
$prev = (($current-1) < 0) ? $total-1 : $current -1;
echo "<a href='image.php?type=image&image_id=".$next."'>Next</a>";
echo " | <a href='image.php?type=image&image_id=".$prev."'>Prev</a>";
// print_r($photos);
数组是正确的,例如我有:
Array ( [0] => 13 [1] => 14 [2] => 15 [3] => 16 )
上一页和下一页没有正确显示。
如果我在图像13上,PREV按钮移动到图像12(图像12属于另一个文件夹),NEXT移动到图像2(而不是14)
我哪里错了?
答案 0 :(得分:0)
您没有将查询结果$photos
用于next / prev。
echo '<img src="images/'.$photos[$current].'.png" alt="my image!" />'; // display current photo
$next = ($current+1) % $total; // modulo
$prev = (($current-1) < 0) ? $total-1 : $current -1;
echo "<a href='image.php?type=image&image_id=".$photos[$next]."'>Next</a>";
echo " | <a href='image.php?type=image&image_id=".$photos[$prev]."'>Prev</a>";