Jump to content

Subquery to get "Photo ??? of ???"


jimmyoneshot

Recommended Posts

I am creating a php image gallery and currently have a query in place which gets all of the details on the current photo being viewed on a user's:-

 


SELECT DISTINCT

(SELECT count(photos.id) FROM photos WHERE photos.author_id = $authorid) AS photo_count,
photos.id,
photos.name,
photoAlbums.id AS album_id,
photoAlbums.name AS album_name

FROM z_photos

LEFT JOIN photoAlbums
ON (photos.album_id = photoAlbums.id)

WHERE photos.id = $photoid AND photos.author_id = $authorid

 

I now need a subquery in the above which somehow gets the position of the photo within the current selection. For example the code posted above is used to show all of the details on a photo posted by the user currently being viewed as well as the count of how many photos the user has posted but above each currently selected photo I want to show a message saying photo ??? of ???. So basically I have the total number of photos from the subquery in the above query but I now need a subquery to get the photos position in the selection. For example if the 'photo_count' produced by the above query was 17 and the user was viewing the second photo it would show photo 2 of 17.

 

How can I do this in one query or via php?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.