This topic is locked
[SOLVED]

 Multiple Inserts for all users

4/26/2019 12:01:45 PM
PHPRunner General questions
T
Tempus_Erus author

I have a table of trainees (trainee table) which consists of individuals - unsurprisingly! 😊
I have a training course table. (training course table).
Each time I add a course to the training course table I would like all the trainees to be 'assigned' the course. In affect, would each 'have their own course'.
I can create a course and assign a trainee no issue by simply selecting a trainee and saving. That training course is only then assigned to who I selected. However this is to labour intensive.
What is the best way to associate all trainees with a course training course once I have entered a new course into the course table?
I have no doubt entirely overthought the process, however, Any help appreciated!
Thanks <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=26399&image=1&table=forumtopics' class='bbc_emoticon' alt=':)' />
Adrian

M
MikeT 4/30/2019

Do you have a join (m:n) table between courses and trainees?
In any case: Personally I would do it with a trigger in the database that creates the records in the joining table after a new course is inserted.

Or you can use an event in phprunner (after insert or similar, I don't have it open so I can't remember the correct title of the events) that does basically the same: Execute the necessary SQL after insertion of a new course. In other words: populate the joining table with the necessary records.

Sergey Kornilov admin 5/1/2019

You will need to implement AfterAdd event of course table to associate trainees with this course. Most likely you will need to loop through trainees table and add a new record for each trainee.

T
Tempus_Erus author 5/2/2019



You will need to implement AfterAdd event of course table to associate trainees with this course. Most likely you will need to loop through trainees table and add a new record for each trainee.


Thanks all,
Sergey,
I used the DB::Query to fetch associated records created an array ad used DB insert. This works well.
A