Jump to content

Need to update 2 tables in 1 go (collecting data from one to go in the second)


Recommended Posts

Hi, i need to update 2 MySQL tables in 1 go using PHP

 

Im posting from a comment form.

 

The tables that i have are;

TABLE: Comments [ commentId ] [ comment ] [ userId ] [ courseId ] [ partId ]

TABLE: Course [ userId ] [ part1_comment ] [ part2_comment ] [ part3_comment ]

 

In the comments table the 'commentId' auto increments.

 

What i want to happen is when someone posts a comment;

 

1) it gets added to the comments table as a new entry

2) the 'commentId' for that entry is recorded and an entry is made in the course table with that 'commentId' being put into the relevant 'part_comment'

 

Im assuming this kind of thing is a 'fairly' regular occurrence so am wondering if theres any best practice ways of approaching it?

 

Also, if theres any potential problems that could occur if many people are posting comments at the same time and how they can be avoided…

 

Any advice would be appreciated.

I assumed as much, what i am currently doing is the following;

 

1) INSERT query into comments table

2) SELECT latest entry from comments table

3) INSERT query into course table (using the data from the latest comments entry)

 

This is working, however im concerned that potentially 100's of people could all be writing comments at the same time and SELECT last entry might not pick up the right comment id...

 

So am wondering if theres a better way?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.