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

时间:2015-10-28 06:54:56

标签: php codeigniter

我无法弄清楚为什么它没有响应。我的代码似乎没有错误,或者可能有错误不仅仅是注意到。提前谢谢。

控制器

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));
            }
    }

2 个答案:

答案 0 :(得分:1)

试试这个

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";
    }       
}

答案 1 :(得分:0)

$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));
            }
    }