开发者

How to store data into multiple tables in Joomla?

开发者 https://www.devze.com 2022-12-22 11:52 出处:网络
I am writing a component and I have a scenerio of storing data into multiple t开发者_如何学Goables with One-To-Many relationship.

I am writing a component and I have a scenerio of storing data into multiple t开发者_如何学Goables with One-To-Many relationship.

Master table is Student and Child table is Student_Subjects.

One student can select multiple subjects.

I want to store the data in Student_subject table with student. Data is submitted from one form where user will be created and subjects will be selected.

Currently I am using JTable Class.

Is there any way to run a transaction query to store the data in both tables? If Yes, then how can i get the student id (auto generated) store it into Student_Subject using the same transaction query batch?

Please guide. Example with code is highly appreciated and needed.


Why would you want to run that simultaneously? You can run 2 queries to do this. First insert your "Student" like so:

$db =& JFactory::getDBO();
$db->setQuery( $query );
$db->query();

Then get the id of the last inserted element like so:

$student_id = $db->insertid();

Now that you have the master id you can do your next insert.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号