【TP5】关于模糊查询

author:咔咔php

wechat:fangkangfkide

 

在俩个表双查数据的时候咱们通常使用的都是关联预加载,可是假如咱们有一个模糊查询的功能时,这个时候关联预加载就挂了code

因此只能使用join视频

 

 

 

/**
     * author:咔咔
     *
     * 获取单个专题下的视频
     * @param $where  查询条件
     * @return array
     */
    public function subjectVideoInfoList($where,$page_index,$page_size)
    {
        if(isset($where['vi_title'])){
            return Db::name('subject_list')
                ->alias('s')
                ->field('s.*,v.vi_id,v.vi_title')
                ->join('video_info v','s.vi_id = v.vi_id')
                ->where([
                    'vs_id'=>$where['vs_id'],
                    'vi_title' => ['like','%'.$where['vi_title'].'%']
                ])->page($page_index,$page_size)->select();
        }else{
            return Db::name('subject_list')
                ->alias('s')
                ->field('s.*,v.vi_id,v.vi_title')
                ->join('video_info v','s.vi_id = v.vi_id')
                ->where([
                    'vs_id'=>$where['vs_id'],
                ])->page($page_index,$page_size)->select();
        }
    }
相关文章
相关标签/搜索