Jump to content

Set Up Tables For N To N Relationship


son

Recommended Posts

I have a form to upload photos with some basic info and would like to be able to select one or several main categories and/or sub-categories to place the image in. If photo is placed in sub-categories only it should also show in relevant main categories of chosen sub-categories later on in web page. How would it be best to set up the tables? Have a separate table for the photo-category combinations and then check in category table if it is a main category or sub-category? What would be best practise?Son

Link to comment
Share on other sites

Just have a field that holds the parent ID, so categories with a parent ID of 0 are top-level categories, and anything else should have the ID of an existing category as the parent ID to indicate that it's a child of that category.

Link to comment
Share on other sites

Just have a field that holds the parent ID, so categories with a parent ID of 0 are top-level categories, and anything else should have the ID of an existing category as the parent ID to indicate that it's a child of that category.
In the categories table and then have a photo_categories table to associate the photos with all relevant categories and sub-categories? Son
Link to comment
Share on other sites

If the photos can be in more than one category, yeah, you need another table for that. You need a photos table, a categories table, and a photo-categories table to hold the mapping.
Cheers. Will have a go ...Son
Link to comment
Share on other sites

Archived

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

×
×
  • Create New...