我的删除和更新按钮不工作?下面是MVC


my delete and update buttons not working? below is the MVC

我不明白为什么它没有响应。我的代码似乎是正确的,没有错误,或者可能有一些错误不是我注意到的。提前谢谢。

控制器

function update()
    {
            if($this->input->post('cancel')){
            $this->index();
            }
            elseif($this->input->post('delete')){
            $this->load->model('Attendance_model');
            $data['getData'] = $this->Attendance_model->getdb();
          $this->Attendance_model->deletedb($this->input->post('delete'));
            $this->input->post('DeptCode');
            }
            elseif($this->input->post('update')){
            $this->load->model('Attendance_model');

型号

function updatedb() {
    foreach($EmpNo as $key=>$row) {
    $data = array('EmpNo'=>$row,
        'EmpName'=>$EmpName[$key],
        'Designation'=>$Designation[$key],
        'DayInTime'=>$DayInTime[$key],
        );
    $this->db->where('EmpNo', $key);
    $this->db->update('AttnDetails', $data);
    }
}
function deletedb($deleteId) {
            foreach($deleteId as $key=>$row) {
    $this->db->delete('AttnDetails', array('ID' => $key));
            }
    }

试试这个

function deletedb($deleteId) {
    $count = count($deleteId);
    if (!empty($count) && $count != 1 ) {
        # if array its come here
        foreach($deleteId as $row) {
        $id = $row['id'];
        $this->db->where('id', $id);
        $this->db->delete('AttnDetails');//table name
        }
    }
    elseif ($count==1) {
        # if single data its come here...
        $id = $deleteId;
        $this->db->where('id', $id);
        $this->db->delete('AttnDetails');//table name
    }
    else{
        # if empty its come here...
        echo "Array is empty";
    }
}

function deletedb($deleteId) {
    $count = count($deleteId);
    if (!empty($count)) {
        foreach($deleteId as $row) {
        $id = $row['id'];
        $this->db->where('id', $id);
        $this->db->delete('AttnDetails');//table name
        }
    }
    else{
        echo "Array is empty";
    }       
}
$data = array('EmpNo'=>$row,
        'EmpName'=>$EmpName[$key],
        'Designation'=>$Designation[$key],
        'DayInTime'=>$DayInTime[$key],
        );

在$data中,删除逗号"DayInTime"=>$DayInTime[$key],

你的数据和模型应该是这样的;

    function updatedb() {
    foreach($EmpNo as $key=>$row) {
    $data = array('EmpNo'=>$row,
        'EmpName'=>$EmpName[$key],
        'Designation'=>$Designation[$key],
        'DayInTime'=>$DayInTime[$key]
        );
    $this->db->where('EmpNo', $key);
    $this->db->update('AttnDetails', $data);
    }
}
function deletedb($deleteId) {
            foreach($deleteId as $key=>$row) {
    $this->db->delete('AttnDetails', array('ID' => $key));
            }
    }