I have problem with my code when i'm trying to save multiple data into database at the same time, this is my code to save into database:
foreach ($data as $value) {
$model->route = $value[0][1];
$model->begin_point = $value[0][2];
$model->begin_point = $value[0][3];
$model->save();
}
return $this->redirect('index');
every i'm trying to save, i'm only get the last data array can save into database. could someone help me? or if someone could provide a tutorial, that would be a real help.
Create a array by looping your multiple values.
Check $bulkInsertArray in not empty
Hope these code is help full.
You can use Yes It Is Batch Insert to insert multiple rows. It is faster than any of the ways stated here :
Check the link for this.
I think batch insert is the best solution for this problem.
but there is one problem with your pic of code that is this code will create only one data row(first row) in data table and update to that same model
solution for your code is
You have to create a New object of the model each time. Or Else youre Just overwriting.
and so on.