justinbriggs1 Posted April 22, 2010 Report Share Posted April 22, 2010 (edited) 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 April 22, 2010 by jwburnside Link to comment Share on other sites More sharing options...
justsomeguy Posted April 22, 2010 Report Share Posted April 22, 2010 You can use the mysql_insert_id function in PHP to get the ID for the last row that was added. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now