Previous/Next PHP
- Started
- Last post
- 10 Responses
- doesnotexist
I'd like to have a simple Previous/Next thing for an image gallery, isi there an easy way to do this? Anyone have a super link they can give me to show me how to do it?
I don't want any weird image slider, ONLY the previous/next links that go to the previous/next image.
- bolus0
like my website?
- bolus0
nevermind... that is different
i don't know anything about php so I can't really help you :(
- acescence0
do you want all this to happen on one page? or do you want each image to be on it's own html page?
- doesnotexist0
it can happen on one page, and yes, like your links, bolus.
- acescence0
there are so many ways you can do this... with a database or flat file to store image names and associated image info, or images hardcoded into an array, or reading the directory on the fly and parsing out the image files
- version30
reading the directory on the fly and parsing out the image files
acescence
(Sep 18 07, 11:39)this sounds fun. could you also choose to sort them by assorted details be it file size, date added or file name with a single file?
- acescence0
yes. here's a bit of php that will read a directory and put anything with .jpg in the name in an array. you could easily add filemtime($file) to return the date and filesize($file) to get size and then sort the array
- doesnotexist0
i dont want to do that, just go through the images. the order they are in as file names is the order i want them to come up in.
- ldww0
I am not sure I understand your question, it seems quite easy, all you need to know is the current image number and the total amount of images. May take an additional query to count the images in the db.
if current greater then 1, display previous link
if current less then total, display next link as current + 1
- welded0
If all your images are named in numeric sequence (img1.jpg, img2.jpg) then ya, all you need to know is how many there are and do as ldww says. It's the kind of thing where you think it's harder than it really is.