codeigniter db-& gt; delete()始终返回true吗? [英] codeigniter db->delete() returns true always?
问题描述
我已经显示了带有记录和删除"图像的表格.在删除图像上单击我正在使用ajax删除记录.假设有3条ID为40、41、42的记录如果我删除ID = 40的记录,则响应返回"1"并删除记录,下次如果我再次单击删除图像",它将再次返回"1".
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()方法始终返回"1"吗?我需要手动检查记录是否存在,然后继续删除吗?下面是我的代码iin ajax.php
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"));
推荐答案
如果删除操作成功,则 db-> delete()返回 TRUE
.如果它不能删除该行,它只会返回 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();
返回数字而不是布尔值,您可以使用If条件对其进行检查.
which returns number and not a Boolean, which you can check with your If conditions.
这篇关于codeigniter db-& gt; delete()始终返回true吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!