CodeIgniter Forums
Check affected_rows() from delete query - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Check affected_rows() from delete query (/showthread.php?tid=39783)



Check affected_rows() from delete query - El Forum - 03-20-2011

[eluser]BandonRandon[/eluser]
Hi,

I'm new to CI. I'm trying to create an employee module and part of that is the delete function. I have created the delete function and it works but for some reason the function I'm using to validate it is returning false.

Here is in my model
Code:
public function delete_employee($id){
        $this->db->delete('employees_table', array('id' => $id));
        if ($this->db->affected_rows() > 0) {
            return TRUE;
        }
        return FALSE;
    }

and my controller
Code:
public function delete_employee($id=''){
            if(empty($id)){
                    $this->session->set_flashdata('error', "error");
                redirect('admin');
            }
            $result = $this->my_model_m->delete_employee($id);
            if($this->employee_m->delete_employee($id)){
                $this->session->set_flashdata('success', "employee Deleted");
                    redirect('admin');
            }
            else{
                $this->session->set_flashdata('error', "error");
                redirect('admin');


            }
        }

This is returning the flash data "error" but deleting the row. If I do a select query it returns true and shows the correct message.