developerdave
07-12-2012, 10:58 PM
I have created an next and prev image link which works great. But I'd like them both to loop back to the beginning or the end when they hit the users last image in their given album.
So I've clicked into my created album '22' and I have image101, image 202 and image243 once I hit image243. I'd like it to return to the albums first image image101.
I'd like same with previous, when I hit Image101 I'd like the link to go back to image243. (Self explanitory).
Each User has their own albums with uploaded images with various photo_id's dependant on how many images the given user has uploaded. So its not in a 1,2,3,4 order.
If I've just uploaded a new image, it will create a photo_id of 244 and if another user in another account uploads an image straight after me, their photo will have a photo image of 245.
The below code is what I have so far, and the next and prev jumps to the next users uploaded image missing out any uploaded images from other user accounts. I just need the next and previous not to hit a blank page after the last image.
I hope I've explained this clearly without giving anyone a headache. Happy to answer any questions if I can get abit of help/advise or guidence.
Thanks
Code used for selecting next/prev user image within the users set album
<?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>";
}
?>
So I've clicked into my created album '22' and I have image101, image 202 and image243 once I hit image243. I'd like it to return to the albums first image image101.
I'd like same with previous, when I hit Image101 I'd like the link to go back to image243. (Self explanitory).
Each User has their own albums with uploaded images with various photo_id's dependant on how many images the given user has uploaded. So its not in a 1,2,3,4 order.
If I've just uploaded a new image, it will create a photo_id of 244 and if another user in another account uploads an image straight after me, their photo will have a photo image of 245.
The below code is what I have so far, and the next and prev jumps to the next users uploaded image missing out any uploaded images from other user accounts. I just need the next and previous not to hit a blank page after the last image.
I hope I've explained this clearly without giving anyone a headache. Happy to answer any questions if I can get abit of help/advise or guidence.
Thanks
Code used for selecting next/prev user image within the users set album
<?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>";
}
?>