wrathican Posted July 7, 2008 Share Posted July 7, 2008 Hey, Thanks for looking. Im having a bit of a problem. Im making a website for a photographer and I showed him a design and a way for him show off his work. The design can be seen here: www.ls12style.co.uk/projects/Wonstar/gallery.php?func=viewal&alid=1 The problem i'm having is that when it comes to displaying the 5 thumbnails at the bottom, i don't know what to do. I mean i can everything from a database no problem but i think what i need is a bit of pagination. what i want to happen is the image in the middle be the current image that is on display and the two images to the left and to the right is that these are the next/previous two images. as you can see from the link, the id of the image to be displayed is taken from the URL. i also want a next and previous button that shows the next image in the 'film strip'. any ideas how i can do this? Thanks in advanced Quote Link to comment https://forums.phpfreaks.com/topic/113594-pagination/ Share on other sites More sharing options...
ag3nt42 Posted July 7, 2008 Share Posted July 7, 2008 flash would be a better way to make this site... however you can do this.. you might look into ajax for this... other wise maybe use alil javascript and simply switch out the images based on which images are there and where the user clicks If using js which is not really recommended. if you can help it... make a big fuction that has the file names it and run a check on which file name is up in the middle then based on that replace the other img src's with the following image in line.. if you do this through php you'll be forced to refresh the page each time.. Quote Link to comment https://forums.phpfreaks.com/topic/113594-pagination/#findComment-583703 Share on other sites More sharing options...
wrathican Posted July 7, 2008 Author Share Posted July 7, 2008 page refresh isnt a problem. but thanks for the help. this is how i thought i might have to do it. Quote Link to comment https://forums.phpfreaks.com/topic/113594-pagination/#findComment-583708 Share on other sites More sharing options...
ag3nt42 Posted July 7, 2008 Share Posted July 7, 2008 np.. if we've solved your problem plz click on solved button below Quote Link to comment https://forums.phpfreaks.com/topic/113594-pagination/#findComment-583714 Share on other sites More sharing options...
anon_login_001 Posted July 7, 2008 Share Posted July 7, 2008 "Pagination" is mostly correct. How to do it, in your case, depends on how the site is designed around that. If you don't have anything in place yet, I suggest taking a look around for some pre-built image gallery solutions. I'm sorry that I don't have a definitive answer for you, but the least I can do is tell you to look up some tutorials on pagination. Basically, you'll need to be able to find out what the previous and next images are in the list/sequence, relative to the current image... which you already said was defined in the URL. This will probably be in the form of a sequential ID from a database, or some such. So it depends on where/how you're retreiving the images. Quote Link to comment https://forums.phpfreaks.com/topic/113594-pagination/#findComment-583721 Share on other sites More sharing options...
wrathican Posted July 7, 2008 Author Share Posted July 7, 2008 well, i have already sort of started work on the gallery. and plus i like the experience. like you guessed the image id in the url is based on the id of the image stored in a DB. the ID the an auto inc. int. but the thing is there might be 50 images belonging to 5 different albums and not all of the 10 images will be next to each other. so the id's of the images belonging to album 3 could go 23,24,25,27,30,37,42,43,50 i guess i would do something like this: <?php $albId = $_GET['albid']; $imgId = $_GET['picid']; //query $query = "SELECT * FROM table WHERE table_albumid='".$albId."'"; // selects all images belonging to the album $result = mysql_query($query); //queries the db while ($row = mysql_fetch_array($result)) { //start a loop? //and then this is where i get stumped. //i imagine i would use an if statement to see if the current image id matches $imgId //then work out which ones are next //but how do i work out the previous? } ?> Quote Link to comment https://forums.phpfreaks.com/topic/113594-pagination/#findComment-583802 Share on other sites More sharing options...
anon_login_001 Posted July 7, 2008 Share Posted July 7, 2008 Are the images associated to the Albums via their IDs as a "Foreign Key" ?? What is the database table layout like? Quote Link to comment https://forums.phpfreaks.com/topic/113594-pagination/#findComment-583820 Share on other sites More sharing options...
mbeals Posted July 7, 2008 Share Posted July 7, 2008 So your "$query = "SELECT * FROM table WHERE table_albumid='".$albId."'";" query returns the ID's in the order you want? You could use the limit function (how I handle pagination). $query = "SELECT * FROM table WHERE table_albumid='$albID' order by `Index` LIMIT $start, 5; Will pull the first 5 records ordered by index starting at image $start. To recenter the film strip, all you need to do is figure out the starting record. Say you need to center on the 10th image. That means the first image of the set will be image 8 (if using 5 images). So all you do is set $start = 8 and it fetches 5 records starting at record 8. It doesn't matter what the image Id's are since you are not ordering by that. Quote Link to comment https://forums.phpfreaks.com/topic/113594-pagination/#findComment-583830 Share on other sites More sharing options...
anon_login_001 Posted July 7, 2008 Share Posted July 7, 2008 mbeals is correct... I should have gleaned the structure from your post, but apparently wasn't paying attention. Sorry. Quote Link to comment https://forums.phpfreaks.com/topic/113594-pagination/#findComment-583835 Share on other sites More sharing options...
wrathican Posted July 7, 2008 Author Share Posted July 7, 2008 oh no problems. i just tried the sql (modified to meet my needs of course) and i got an error. it said unknown column Index. but this would probably be the best way so far. Quote Link to comment https://forums.phpfreaks.com/topic/113594-pagination/#findComment-583845 Share on other sites More sharing options...
mbeals Posted July 7, 2008 Share Posted July 7, 2008 i was just throwing 'Index' out there because I didn't know your db structure. replace 'Index' with the name of whatever column you want to sort the results by. This is usually (but doesn't have to be) one of the indices. You probably could eliminate the 'order by' statement all together, but it's pretty poor practice. Quote Link to comment https://forums.phpfreaks.com/topic/113594-pagination/#findComment-583869 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.