Jump to content

Relational Database Design Issue


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

Edited by jwburnside
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...