Answer the question
In order to leave comments, you need to log in
How to correctly add data to related tables?
There are 2 tables - tbl_1 and tbl_2.
The tbl_2.parent_id field points to (equals to) the tbl_1.id field.
Those. table data is linked.
The question itself: how to insert data into both tables at once, if I cannot know the id of the parent record until I insert it?
So far the algorithm is:
Answer the question
In order to leave comments, you need to log in
https : //dev.mysql.com/doc/refman/5.0/en/getting-un... .
I draw your attention to the fact that this variable is stored at the connection level, that this is not a request - there will be no search, just a request for a value from the server's memory.
Your algorithm:
I think is right. If this is WEB programming, then the data from the first table can be put in <select>
together with the ID and added.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question