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"));
CodeIgniter 4 Model delete() methodTakes a primary key value as the first parameter and deletes the matching record from the model's table: If the model's $useSoftDeletes value is true, this will update the row to set deleted_at to the current date and time.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With