Я использую модель MVC, фреймворк CodeIgniter. Я пытаюсь вставить 14 строк в свою БД, когда пытаюсь вставить меньше (например, 9 или 10) строк, которые работают. Я не понимаю лог c. Массив $ data принимает все 14 строк, но по какой-то причине БД не принимает его.
Это контроллер:
public function saveFinalShifts(){
$data = array();
$newDate= $this->input->post('week');
$sunday = $this->Shifts_model->getStartDate($newDate);
$dates = array_fill(0,14,$sunday);
$days = $this->input->post('day[]');
$times = $this->input->post('time[]');
$worker_names = $this->input->post('worker_name[]');
if(is_array($dates)){
foreach ($dates as $key => $date){
$data[] = array (
'date' => $date,
'day' => $days[$key],
'time' => $times[$key],
'worker_name' => $worker_names[$key],
);
}
}
$this->session->set_flashdata('success', 'Submitted!');
$this->Shifts_model->saveFinalShifts($data);
redirect(base_url("/Shifts/manageShifts"));
}
Это моя модель:
public function saveFinalShifts($data) {
$this->db->db_debug = FALSE;
$error = NULL;
if (!$this->db->insert_batch('final_shifts', $data)) {
$error = $this->db->error();
}
return $error;
}
Когда я пытаюсь: echo '<pre>';print_r($data); die;
Вы можете убедитесь, что каждая из 14 строк находится в массиве $ data.
Array
(
[0] => Array
(
[date] => 2020-05-10
[day] => sunday
[time] => morning
[worker_name] =>victoria
)
[1] => Array
(
[date] => 2020-05-10
[day] => monday
[time] => morning
[worker_name] => victoria
)
[2] => Array
(
[date] => 2020-05-10
[day] => tuesday
[time] => morning
[worker_name] => victoria
)
[3] => Array
(
[date] => 2020-05-10
[day] => wednesday
[time] => morning
[worker_name] => victoria
)
[4] => Array
(
[date] => 2020-05-10
[day] => thursday
[time] => morning
[worker_name] => victoria
)
[5] => Array
(
[date] => 2020-05-10
[day] => friday
[time] => morning
[worker_name] => victoria
)
[6] => Array
(
[date] => 2020-05-10
[day] => saturday
[time] => morning
[worker_name] => victoria
)
[7] => Array
(
[date] => 2020-05-10
[day] => sunday
[time] => evening
[worker_name] => victoria
)
[8] => Array
(
[date] => 2020-05-10
[day] => monday
[time] => evening
[worker_name] => victoria
)
[9] => Array
(
[date] => 2020-05-10
[day] => tuesday
[time] => evening
[worker_name] => victoria
)
[10] => Array
(
[date] => 2020-05-10
[day] => wednesday
[time] => evening
[worker_name] => victoria
)
[11] => Array
(
[date] => 2020-05-10
[day] => thursday
[time] => evening
[worker_name] => victoria
)
[12] => Array
(
[date] => 2020-05-10
[day] => friday
[time] => evening
[worker_name] => victoria
)
[13] => Array
(
[date] => 2020-05-10
[day] => saturday
[time] => evening
[worker_name] => victoria
)
)