I'm using this script to move between images:
$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 is correct, I have for exemple:
Array ( [0] => 13 [1] => 14 [2] => 15 [3] => 16 )
Problem:
Prev and Next not are correctly displayed.
For Instance:
If I'm on image 13, PREV button move to image 12 (image 12 belong another folder) and NEXT move to image 2 (instead 14)
Where am I going wrong?