I have data like this student_id=1 and class_id=1,2,3 (class id can be multiple) in my controller.
And i want result in mysql table like this:
I have data like this student_id=1 and class_id=1,2,3 (class id can be multiple) in my controller.
And i want result in mysql table like this:
Make a new middle-table called studentclass with Id being the primary key and Student_Id and Class_Id as foreign keys pointing to their tables. You can then store the Id of studentclass as foreign key in the students table.
Here's an example for better understanding:
Student Id (Primary) StudentClass_Id (foreign key)
StudentClass Id (Primary) Student_Id (Foreign key) Class_Id (Foreign key)
You should use any functions like split to make an array from string separated by comma. And you can insert the row in MySQL through looping the array