mysql 中 find_in_set 函数的使用方法

 

 

//4. 根据cate和city 筛选学校 [ 排行榜使用 ]
    public function getSchoolListByCateCity($where,$num,$path) {
        //1. 搜索条件
        if (!empty($where['city_id'])) {
            $data[] = "city_id = ".$where['city_id'];
        }
        if (!empty($where['area_id'])) {
            $data[] = "find_in_set(".$where['area_id'].",area_ids)";
            //find_in_set 函数 ($id,'se_cate_id') 第一个参数id  第二个参数字段名称
        }
        $data[] = 'status=1';
        //2. 排序条件
        $order = ['id' => 'desc'];
        //3. 字段
        $field = 'id,name,url_name,logo,city_id,add_count,class_path,teacher_id,tel,kefu,is_vip';
        $res = $this->where(implode(' AND ',$data))
            ->order($order)
            ->field($field)
            ->paginate([
                'list_rows'=>$num,
                'path' => $path,
            ]);
        //echo $this->getLastSql();
        return $res;
    }

 

posted @ 2022-05-22 17:23  棉花糖88  阅读(39)  评论(0)    收藏  举报