I have a database that stores image urls andother data, I want a gallery to display them but because the site is public I may want to delete some images. When a user uploads an image source and title, it is inserted into the database with an auto increment unique ID. The current script only adds or subtracts 1 from the ID to display the next or previous image. Is there any better way of doing this? My current script:
function image_control($id){
$next=$id+'1';
$prev=$id-'1';
$query = "SELECT MAX(id), MIN(id) FROM mp_images";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
$max = $row['MAX(id)']; $min = $row['MIN(id)'];
}
if($next==$max+"1"){$next=$min;} if($prev==$min-"1"){$prev=$max;}
echo "<a href='".$next."'>Next Image</a> <a href='".$prev."'>Previous Image</a>";
}
An example of this failing would be images where the ID's are 3,4,5,7,8.