I'm writing an element and I've got a scenerio of storing data into multiple tables with One-To-Many relationship.
Master table is Student and Child table is Student_Subjects.
One student can choose multiple subjects.
I wish to keep data in Student_subject table with student. Information is posted in one form where user is going to be produced and subjects is going to be selected.
Presently I'm using JTable Class.
Can there be in whatever way to operate a transaction query to keep the information both in tables? If So, then how do i obtain the student id (auto produced) store it into Student_Subject utilizing the same transaction query batch?
Please guide. Example with code is extremely appreciated and needed.
Why would you need to run that concurrently? You are able to run 2 queries to get this done. First place your "Student" like so:
$db =& JFactory::getDBO(); $db->setQuery( $query ); $db->query();
Then obtain the id from the last placed element like so:
$student_id = $db->insertid();
Now that you've got the actual id that you can do the next place.