Wednesday 15 July 2015

sql - INSERT INTO a table from another table, but with the correct user ID for each comment a user adds -


I have two tables - one 'user' and 'comments'. Both of them have 'IDUsers' column when a user adds a comment, I want them to come from their User ID 'User' table and go to 'IDUs' column from the 'idusers' column in the 'Comment' table.

However, a comment is being added to the user at the same time - so I am using INSERT I for new information. I'm also using coldfusion - if it makes a lot of difference.

Hope everyone understands what I am saying ... and thanks for the help.

What is the problem really? When a user is posting a comment, you know his user ID, then use the urid to insert it in the comments table.

If you are creating user objects on the fly - as a part of the same transaction (make sure it is a transaction! It is important - the sync issue !!!) - like some mysql_insert_id () After inserting the equal user table in ColdFusion (), get the ID of the recorded record; Use that ID as a foreign key in the comment record.


No comments:

Post a Comment