用户
 找回密码
 入住 CI 中国社区
搜索
查看: 9064|回复: 11
收起左侧

[讨论/交流] 如何进行批量删除呢????

[复制链接]
发表于 2009-12-28 14:34:15 | 显示全部楼层 |阅读模式
function deleteseat($id)
{
  if($id!=0)
   {
   $this->db->delete("city",array("id"=>$id));
   return true;
   }
   else
   {
     $ValidDealers=$this->input->post('id');
  print_r($ValidDealers);
     $this->db->where_in('id',array(($ValidDealers)));
      $this->db->delete('city');
      return true;
   
   }
}

我的 $ValidDealers获得了是数组Array ( [0] => 1 [1] => 2[2] => 3) 但是删不成功?这是为什么呢?
发表于 2009-12-28 15:10:39 | 显示全部楼层
Active Record 的 delete 不支持 where_in
 楼主| 发表于 2009-12-28 20:03:46 | 显示全部楼层
那要怎么写sql语句呢?
发表于 2009-12-28 22:25:11 | 显示全部楼层
Active Record 的 delete 不支持 where_in
Hex 发表于 2009-12-28 15:10


用原生的sql语句可以吧
$query_string = "delete from ...";
$this -> db -> query($query_string);
发表于 2009-12-29 02:27:24 | 显示全部楼层
应该支持,我一直是这么用正常.
function delRecords($id)
{
$this->db->where_in('id',$id);
$this->db->delete('news');
}
$id为一维数组.
发表于 2009-12-29 12:36:32 | 显示全部楼层
不清楚,支持
 楼主| 发表于 2009-12-29 15:52:22 | 显示全部楼层
where_in不支持的我后来我改了sql与句就好了
function deletecity($id)
        {
         if($id!=0)
          {
          $this->db->delete("city",array("id"=>$id));
          return true;
          }
          else
          {
          
           $arr=$this->input->post('id');
           $sql="delete from `city` where id in (".join(',',$arr).")";
           $query=$this->db->query($sql);
       return true;

          }
        }
 楼主| 发表于 2009-12-29 15:53:23 | 显示全部楼层
把它写成SQL就完成批量的,我这是一种方法
发表于 2010-1-4 13:03:23 | 显示全部楼层
这个支持呀!
发表于 2010-1-4 18:46:45 | 显示全部楼层
where_in不支持的我后来我改了sql与句就好了
$arr=$this->input->post('id');
$sql="delete from `city` where id in (".join(',',$arr).")";
...
stutrip 发表于 2009-12-29 15:52

input->post()只能过滤跨站脚本攻击(XSS),无法抵御SQL注入
红字部分没有安全检测,存在注入漏洞,建议用foreach检测每个id为数字类型if(is_int($val))

本版积分规则