Jump to content

Relational Database Design Issue


justinbriggs1

Recommended Posts

Hey everyone, I was wondering if someone could help me out with an amateur design question. Let me try to sum it up:I have three tables:images (IMAGE_ID, IMAGE_NAME)categories (CATEGORY_ID, CATEGORY_NAME)image2cat (IMAGE2CAT_ID, IMAGE_ID, CATEGORY_ID)Simply a M:M relationship between images and categories that I normalized with the image2cat table.My question is, when I write this out in Mysql and PHP, what is the correct way to write the query so that it inserts the new image name, but also adds the corresponding entry into the image2cat table as well?i.e INSERT INTO images (IMAGE_NAME)VALUES ('new_imagename')INSERT INTO image2cat (IMAGE_ID, CATEGORY_ID)VALUES ('image_id')How do I get IMAGE_ID? Do I need another query to get the newly created record? Or am I going about this the wrong way?Thanks, any help would be appreciated.JW

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...