tp5模糊查询,分页加分页后数据处理

 public function search ()
    {
        // if(request()->isPost()){
            //获取输入的类别
            $where=[];
            $where1=[];
            $sousuo=input('sousuo');
            // var_dump($sousuo);
            $where['name']=['like',"%$sousuo"];
            $where1['name']=['like',"$sousuo%"];
            $sql=db('goodstype')->where($where)->whereOr($where1)->column('id');
            // var_dump($sql);
            //根据类别查商品
            if($sql){
                $isok=db('goodsadd')->where('tid','in',$sql)->order('id desc')->paginate(12, false, ['query' => ['sousuo' => $sousuo]])->each(function($items,$key){
                    $items['imgs'] = explode(',',$items['imgs']); //用逗号把字符转换为数组
                    return $items;
                });
                // var_dump($isok);
                $this->assign('isok',$isok);
            }else{
                //查询商品名称
                $where=[];
                $where1=[];
                $where['title']=['like',"%$sousuo"];
                $where1['title']=['like',"$sousuo%"];
                $where['shorttitle']=['like',"%$sousuo"];
                $where1['shorttitle']=['like',"$sousuo%"];
                $isok=db('goodsadd')->where($where)->whereOr($where1)->order('id desc')->paginate(12, false, ['query' => ['sousuo' => $sousuo]])->each(function($items,$key){
                    $items['imgs'] = explode(',',$items['imgs']);
                    return $items;
                });;
                // var_dump($isok);
                $this->assign('isok',$isok);
                
                
            }
            $aa=$isok->render();
            $this->assign('aa',$aa);
            $this->assign('sousuo',$sousuo);


        // }
posted @ 2020-08-13 09:09  不吃肉的羊  阅读(441)  评论(0编辑  收藏  举报