Jump to content

Avoiding duplicate records in a M:M relationship


justinbriggs1

Recommended Posts

Hey everyone, I have a query that is basically just retrieving a list of images and the categories that they can be assigned to, like this:$imageinfo_query = mysql_query("SELECT pd_categories.CATEGORY_TYPE, pd_images.IMAGE_FILEFROM pd_images, pd_imagecatlink, pd_categoriesWHERE pd_imagecatlink.IMAGE_ID = pd_images.IMAGE_IDAND pd_imagecatlink.CATEGORY_ID = pd_categories.CATEGORY_IDThen I display it like this:while($imageinfo_array = mysql_fetch_array( $imageinfo_query )) {<?php echo $imageinfo_array['IMAGE_FILE'] ; ?><?php echo $imageinfo_array['CATEGORY_TYPE'] ; ?> }Works fine, but since each image is assigned to more than one category, I get a duplicate image for each category. How do I adjust my query or the output to just display the image, and then a list of the categories? Any help would be appreciated.JW

Link to comment
Share on other sites

That's not an issue with the query, you need to do that in PHP. You can keep track of which image you printed last and if the current row is the same image then you just print a new category for the existing image.

Link to comment
Share on other sites

That's not an issue with the query, you need to do that in PHP. You can keep track of which image you printed last and if the current row is the same image then you just print a new category for the existing image.
Cool, thanks. I am still having a few issues but I will post to PHP board.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...