I've set up a simple gallery system in PHP that is built to display one image per page. My URL parameter simply uses a gallery variable and a page variable and does not use the image iD in any way to pull the image. This is because I'm setting my htaccess settings to make a friendly URL:
http://mysite.com/images/1/
^ Would pull the first image in my MySQL query
or
http//mysite.com/images/12/
^ Would pull the 12th image in my MySQL query
The PHP page would then look like:
images.php?gallery=images&page=1
and
images.php?gallery=images&page=12
The queries (simplified) would then look like this for each of the above:
For the first image:
SELECT id, img_src
FROM pictures
WHERE gallery = images
ORDER BY date_added DESC
LIMIT 0, 1
and for the 12th image:
SELECT id, img_src
FROM pictures
WHERE gallery = images
ORDER BY date_added DESC
LIMIT 11, 1
It's been working great but I ran into a problem now that I want to add a feature. I was hoping to display thumbnails of the ten most recently added images to the database no matter which gallery they belong to… i.e. this query:
SELECT id, gallery, img_src
FROM pictures
ORDER BY date_added DESC
LIMIT 10
Is there any way I can know which 'position' or 'page' each image would be for the specific gallery so that I can create the link correctly?
For example, say the ten most recent thumbnails return 4 pictures from the gallery 'images', then 2 pictures from the gallery 'weddings', then 3 pictures from the gallery 'portraits' and then one more image from the gallery 'images', so my links should then be:
http://mysite.com/images/1/
http://mysite.com/images/2/
http://mysite.com/images/3/
http://mysite.com/images/4/
http://mysite.com/weddings/1/
http://mysite.com/weddings/2/
http://mysite.com/portraits/1/
http://mysite.com/portraits/2/
http://mysite.com/portraits/3/
http://mysite.com/images/5/
Thanks for any help. I'm sure I'm overlooking something stupid easy here but I'm hoping to do it most efficiently as far as programming goes. So far my thoughts are that when I'm looping through the output I have to somehow retain each gallery's 'image count' and add one to this count each time an image of that gallery is added.