tp3.2中批量删除 批量添加数据

M('tablename')->where("id in (1,2,3,4,5)")->delete(); // 删除tablename 表中id 为1,2,3,4,5 的5条数据。要批量删除,改一下where 调教就行了

public function batCreatePlace($data)
    {
        $area_id = isset($data['area_id'])?$data['area_id']:'';
        $num = isset($data['num'])?$data['num']:'';
        if(empty($area_id))
        {
            $this->addErr('943001');
            return false;
        }
//        $area_id_arr=explode(",",$area_id);
//        foreach ($area_id_arr as $k=>$v)
//        {
//            $area_add[] = ['area_id'=>$v];//'area_id=>'.$v;
//        }
        for ($i=1;$i<=$num;$i++)
        {
            $area_add[]=['area_id'=>$area_id];
        }
        $data=M('place')->addAll($area_add);
        if(!$data)
        {
            $this->addErr('943025');//批量新增车位失败
            return false;
        }
        $this->addData(__FUNCTION__, $num);
        return true;
    }

  

posted @ 2019-11-24 18:29  PHP小媛  阅读(440)  评论(0编辑  收藏  举报