flevian
flevian

Reputation: 31

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

i cant figure out why it is not responding.my code seem right with no errors, or may be there are errors that am not just noticing. thanks in advance.

controller

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

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

Upvotes: 2

Views: 75

Answers (2)

ydlgr
ydlgr

Reputation: 57

$data = array('EmpNo'=>$row,

        'EmpName'=>$EmpName[$key],

        'Designation'=>$Designation[$key],

        'DayInTime'=>$DayInTime[$key],
        );

In you $data, delete the comma 'DayInTime'=>$DayInTime[$key],

Your data and model should be like this ;

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

Upvotes: 0

Abdulla Nilam
Abdulla Nilam

Reputation: 38609

Try this

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

}

or

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

Upvotes: 1

Related Questions