I have a gallery with thumbnail pictures that when selected bring up the larger image. On the larger image I have "next" and "previous" buttons to loop through just the larger images one at a time.
So far the buttons work, but I need to be able to specify the first id-key in the range so that you can't go back any further, and likewise the last id-key so that you can't go past the last image (within the specified criteria).
I am posting an idea of what I think it should look like but obviously it doesn't work. Maybe someone can fix it or give me some ideas of how to get around this problem.
Code: Select all
<?php
function shownext ($gallery_id) {
$self = "page.php";
$gallery_id = $_GET['gallery_id']; //id selected from thumbnail gallery
$query = "SELECT MAX(gallery_id) FROM gallery WHERE foldername='2003' AND location='gallery'";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result);
$max_id = $row['gallery_id']; //this needs to be the highest id key available within the above criteria
if ($gallery_id < $max_id) {
$nextid = $gallery_id + 1;
$next = "$self?gallery_id=$nextid";
} else {
$next = "$self?gallery_id=$max_id";
}
echo $next;
}
function showprev ($gallery_id) {
$self = "large2003.php";
$gallery_id = $_GET['gallery_id']; //id selected from thumbnail gallery
$query = "SELECT MIN(gallery_id) FROM gallery WHERE foldername='2003' AND location='gallery'";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result);
$min_id = $row['gallery_id']; //this needs to be the lowest id key available within the above criteria
if ($gallery_id > $min_id) {
$prev_id = $gallery_id - 1;
$prev = "$self?gallery_id=$prev_id";
} else {
$prev = "$self?gallery_id=$min_id";
}
echo $prev;
}
?>feyd | Please use
Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]