How implement Next and Previous buttons?
Moderator: General Moderators
How implement Next and Previous buttons?
I'm creating a photo gallery. The file name and path to the file are all stored on MySQL database. Once I receive an ID on which thumbnail the user click, I display the full image on the page. I got the display worked out but I want to implement the Next and Previous button on this page so the user can click on these two buttons to move around instead of going back to the thumbnails. Once there is no next or previous picture, I want to disable the button. How do I go about doing this?
Any help is appreciated!
ljCharlie
Any help is appreciated!
ljCharlie
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
There are so many ways you can do this depending on how you have things set up. The basic principle is to check to see if it is the first picture being displayed or the last - as this is when you need to hide buttons. To do this you need to know from either the database or id numbers that it is the first picture - e.g. you made a database query with LIMIT 0,1 on the end.
Then to work out the last photo you need to have counted all the photos in the album and then check to see if that photo is the last.
Check out the class in my signature link as it may help you.
Then to work out the last photo you need to have counted all the photos in the album and then check to see if that photo is the last.
Check out the class in my signature link as it may help you.
Many thanks for the suggestion but here is what I have so far. I have this query: to query all the pictures in the database base on section ID and display them as thumbnails on the left side of the browser in an iframe. Now when the user click a thumbnail, a picID will be passed back to the _parent window and display the full picture. So I guess my question is, how do I figure out the position of the picture that the user click so I can determine if the button needs to be disabled or not? What codes do I need to have to determine this position and compare them to test if it is the last or the first? I tried holding the position in an array but the array values get discarded once the page is reload.
ljCharlie
Code: Select all
$query_rsSection = "SELECT * FROM photoGallery WHERE sectionID = ".$sectnID;ljCharlie
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
You can use the order that they are selected from the database - when you select all the photos from an album they will come in an order - sorted by the picture id, or name or something. So you can either place this in an array, or when you lay the thumbnails out you can give them id's in the links - so the first is 1 and the last is x, then you can see that the picture is 1 and know its the first. Then you can count the total number of pictures and then check to see if the current photo is the last.
It all depends on how you store your photo album. You could have unique photo numbers for each album - and so these can be sued to order them. You could hold a list of photos to be in an album in a kind of link list and use this to determin the position.
Im sure you understand the principle of checking a number - its just a case of passing that number to the page that shows the full photo.
It all depends on how you store your photo album. You could have unique photo numbers for each album - and so these can be sued to order them. You could hold a list of photos to be in an album in a kind of link list and use this to determin the position.
Im sure you understand the principle of checking a number - its just a case of passing that number to the page that shows the full photo.
All the photos have a unique picID and also a section ID. If all the photos belong to a section ID, say 100, then display all of them as thumbnails. During the process of displaying these pictures as thumbnail, I also store their picID into an array so I can sort, count, or access them. The problem is that once the user click on the thumbnail to display the full picture by reloading the page, the array gets discarded because PHP is a server side. How do over come this so I can access the array later or whenever I want to?
ljCharlie
ljCharlie
It's the not the page I'm worry about. It's the picture. For example, there are 5 pictures in section 100 and those 5 pictures are displayed as thumbnails on the left side in an iframe. When the user click on the picture 3, a full picture is display on the main area which is on the right side of the page. Now, when the user click on the next button on the buttom of the full picture, the picture number 4 should replaced picture number 3 in full size and so on until the last picture which is picture number 5. If the current picture displayed in full size is picture number 5 then disable the Next button. And do the same for the previous button too. When the first picture is displayed in full size then disable the previous button. I don't think this involves pagination and limits in the query.
ljCharlie
ljCharlie
You're PHP page will have the picture ID stored in it, as it's used to run the query to get the picture path. The 'next' and 'previous' buttons can just pass (the current picture id) +/- 1 respectively, through the URL.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.