它总是保存新记录,即使该ID上已经有时间了。如果timein已经在数据库中,我如何添加超时。\
请帮忙,谢谢。。。在我的控制器中。。。
public function save() {
$v_id = $this->input->post('v_id');
$date = date('Y-m-d');
$time = date('h:i:s A');
//check if record exist
$this->form_validation->set_rules('v_id','Plate Number','trim|callback_get_record');
//if record not found
if($this->form_validation->run()==FALSE){
//show error
$this->session->set_flashdata('error', 'Cannot find QRCode number '.$v_id);
redirect('attendance/create');
}
else{
//check if already timein in
$signin = $this->attendance_model->checktimein($v_id);
//if timein found
if($signin==TRUE){
$this->attendance_model->update(array('V_ID'=>$v_id,'TIMEOUT' => $time,'STATUS' => 1));
$this->session->set_flashdata('success', 'Successfully Time OUT '.$v_id);
redirect('attendance/create');
}
else{
$this->attendance_model->save(array('V_ID'=>$v_id,'TIMEIN' => $time,'LOGDATE' => $date,'STATUS' => 0));
$this->session->set_flashdata('success', 'Successfully Time IN '.$v_id);
redirect('attendance/create');
}
}
}
public function get_record($v_id){
$row = $this->db->where('v_id',$v_id)
->get('vehicle_info')
->num_rows();
if($row == 1){
return TRUE;
}else{
return FALSE;
}
}
它总是保存新记录,即使ID上已经有时间。如果数据库中已经有时间,我该如何添加超时。\
请帮忙,谢谢。。。
在模型中时。。。
public function checktimein($v_id){
$row = $this->db->where('V_ID',$v_id)
->where('LOGDATE',$date)
->where('STATUS',0)
->get('attendance')
->num_rows();
if($row > 0){
return TRUE;
}else{
return FALSE;
}
}
public function save($data){
$this->db->where('V_ID',$data['v_id']);
$this->db->insert('attendance',$data);
}
public function update($data){
return $this->db->where('V_ID',$data['v_id'])
->update('attendance',$data);
}
兄弟,您在这里错过了$date
$signin = $this->attendance_model->checktimein($v_id);
如果在查询中使用$date作为LOGDATE ,则必须将日期作为参数传递
$signin = $this->attendance_model->checktimein($v_id,$date);
public function checktimein($v_id,$date){