我有以下方法我想更新当前页面中的记录..通过attendance_id但它更新所有记录..如何可以避免这个
function manage_teacher_attendance_update($timestamp = '')
{
$running_year = $this->db->get_where('settings' , array('type' => 'running_year'))->row()->description;
$active_sms_service = $this->db->get_where('settings' , array('type' => 'active_sms_service'))->row()->description;
$attendance_of_teachers = $this->db->get_where('teacher_attendance', array('year'=>$running_year,'timestamp' => $timestamp))->result_array();
foreach($attendance_of_teachers as $row) {
$attendance_status = $this->input->post('status_'.$row['attendance_id']);
$leave_status = $this->input->post('leave_status'.$row['attendance_id']);
$this->db->where('attendance_id' , $row['attendance_id']);
$this->db->update('teacher_attendance' , array('status' => $attendance_status,'leave_status' => $leave_status));
}
$this->session->set_flashdata('flash_message' , get_phrase('attendance_updated'));
redirect(base_url().'index.php?admin/manage_teacher_attendance_view/'.$timestamp , 'refresh');
}
让我说如果我更新它的几个选定的选项并更新它..下次我选择一些其他选项并更新它..删除我之前更新的所有内容
答案 0 :(得分:1)
尝试使用
$this->db->flush_cache();
$this->db->where('attendance_id' , $row['attendance_id']);
$this->db->update('teacher_attendance' , array('status' => $attendance_status,'leave_status' => $leave_status));
它将更新从上面的查询中获取attendance_id的所有记录