i have displayed table with record and "Delete" image. on delete image click i am deleting the record using ajax. supose there are three records with id 40,41,42 if i delete record with ID = 40, responce returns "1" and record gets deleted, next time if i again click on delete image it again returns "1".
codeigniters db->delete() method returns "1" always ? do i need to check manually if record exists and then proceed to delete ? below is my code iin ajax.php
$res = $this->db->delete(tbl_user_groups, array('owner_id' => $admin,'user_group_id'=>$gid));
if($res) echo json_encode (array("success"=>"true"));
else echo json_encode (array("success"=>"false"));
The db->delete() returns TRUE
, if delete operation is successful. It would only return FALSE
if it COULDN’T delete the row. I think you should be checking something like:
$this->db->affected_rows();
which returns number and not a Boolean, which you can check with your If conditions.