如何使用多个数组更新表数据,无法理解但是尝试 只有一个记录更新。
roaster_detail表将由$ array4数据更新。 我添加了3张图片:
我的代码是:
$array4 = array_chunk($array3, 1);
foreach ($array4 as $result) {
$roaster_detail = $this->RoasterDetail->query("Select * FROM roaster_details WHERE roaster_details.date = '$date_' AND roaster_details.shift_name_time = '$nishift_name_time3' AND roaster_details.status = 'back data' limit 0,1");
if (!empty($roaster_detail['0']['roaster_details']['id'])) {
$this->request->data['RoasterDetail']['id'] = $roaster_detail['0']['roaster_details']['id'];
}
$this->request->data['RoasterDetail']['emp_id'] = $result[0];
$this->request->data['RoasterDetail']['roasters_histories_id'] = $data['id'];
$this->request->data['RoasterDetail']['status'] = 'up data';
$this->RoasterDetail->create();
$this->RoasterDetail->save($this->request->data['RoasterDetail']);
}
当我打印 $ array4 时,请查看:
当我打印 $ roaster_detail 时,请查看:
表记录:
我的要求是:更新所有记录。现在只更新一条记录。
答案 0 :(得分:0)
你应该使用saveAll();在循环
中使用模型时,而不是save()函数 $this->RoasterDetail->saveAll($this->request->data['RoasterDetail']);