ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
​ 1.查询关联的id,并且处理好,可以不用下面那么麻烦 ~~~php $search=$this->request->param('search'); $newidlist=array(); if($search){ $idlist=Db::table('user')->where(array('nick_name'=>array('like','%'.$search.'%')))->select(); $newidlist=array(); foreach ($idlist as $k=>$v){ $id=$v['id']; array_push($newidlist,$id); } $newidlist=implode(",", $newidlist); } ~~~ ![](data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw== "点击并拖拽以移动") 2.修改$total,user\_id为待查询的字段 ~~~php $total = $this->model->where($where); if ($newidlist){ $total = $total->where('user_id','in',$newidlist); } $total =$total ->order($sort, $order)->count(); $contsql=$this->model->getLastsql(); $contsql=str_replace("( `id` LIKE 0 ) AND","",$contsql); $total = Db::query($contsql)[0]['tp_count']; ~~~ ![](data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw== "点击并拖拽以移动") 3.修改$list ~~~php $list = $this->model->where($where); if ($newidlist){ $list = $list->where('user_id','in',$newidlist); } $list = $list->order($sort, $order) ->limit($offset, $limit) ->select(); $sql=$this->model->getLastsql(); $sql=str_replace("( `id` LIKE 0 ) AND","",$sql); $list = Db::query($sql); $list = $this->array_to_object($list); ~~~ ![](data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw== "点击并拖拽以移动") 4.引入Db类 5.引入数组转对象方法 ~~~php /** * 数组 转 对象 * * @param array $arr 数组 * @return object */ public function array_to_object($arr) { if (gettype($arr) != 'array') { return; } foreach ($arr as $k => $v) { if (gettype($v) == 'array' || getType($v) == 'object') { $arr[$k] = (object)($this->array_to_object($v)); } } return (object)$arr; } ~~~ ![](data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw== "点击并拖拽以移动") 点击链接加入群聊【ThinkPHP56小功能】:[正在跳转](https://jq.qq.com/?_wv=1027&k=Z0c641WP "正在跳转")  ​