Multiple image output?

Hi, I have a page with multiple image image galleries for which I use the following output:


<cfoutput query="getGalleries" group="gallery_id">
  <div id="gallery" class="lightboxGallery">
    <h2>#getGalleries.gallery_name_eng#</h2>
    <cfloop index="currentrow" from="1" to="#getGalleryPhotos.recordCount#">
      <cfoutput>
      <a href="gallery_photos/photos/#getGalleryPhotos.photo[currentrow]#" class="lightbox"><img src="gallery_photos/thumbnails/#getGalleryPhotos.photo[currentrow]#" alt="" /></a>
       </cfoutput>        
    </cfloop>
  </div>
</cfoutput>

This gives me the right number of galleries but for som, for me unknown reason not the right number of images per gallery. In stead it gives the number of images in a certain gallery multiplied by the total number of images in the database. This are the queries I’m using:


SELECT
        gallery_id
     ,  gallery_name_eng
     ,  gallery_name_gre 
FROM
        galleries

SELECT DISTINCT
       photo_id
     , gallery_id
     , photo
     , description
FROM
       gallery_photos
WHERE
       gallery_id = #getGalleries.gallery_id#

But the DISTINCT isn’t working in this case. In my test case I have 2 galleries in the database. One with 4 images and one with three. The output from above indeed gives me 2 galleries but instead of 1 with 4 and the other with three images it gives me 1 with 28 images and the other with 21 (number of images in the gallery x the total number of images in the gallery_photos table)

What should I shange so I get the right number of images?

Thank you in advance

DISTINCT ~always~ works

perhaps it doesn’t produce what you think it should, but it does work

you show two queries, but i’m getting the feeling you’re doing the second one inside a loop driven by the output of the first, and i would change this before doing anything else