• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php多表查询再加分页的实现求大牛看看

php 搞代码 4年前 (2022-01-23) 21次浏览 已收录 0个评论
文章目录[隐藏]
<code>public function my_join_activity(){        header('Content-type:text/html;charset=utf-8');        $Model=M();        $unionid=session('unionid');        if(!$unionid){            $inde=A('Index');            $inde->login();        }        //使用原生sql进行多表查询 注意where条件的and语句        $list=$Model->query("select * from activity,apply where apply.ac_id=activity.ac_id and apply.unionid='{$unionid}' order by ap_id des<span>%本文来源gaodai#ma#com搞*代#码9网#</span><strong>搞gaodaima代码</strong>c");        $this->assign('list',$list);        $this->display();    }</code>

用的是tp框架 sql中怎么分页 比如一页显示5个数据 怎么做呢

回复内容:

<code>public function my_join_activity(){        header('Content-type:text/html;charset=utf-8');        $Model=M();        $unionid=session('unionid');        if(!$unionid){            $inde=A('Index');            $inde->login();        }        //使用原生sql进行多表查询 注意where条件的and语句        $list=$Model->query("select * from activity,apply where apply.ac_id=activity.ac_id and apply.unionid='{$unionid}' order by ap_id desc");        $this->assign('list',$list);        $this->display();    }</code>

用的是tp框架 sql中怎么分页 比如一页显示5个数据 怎么做呢

用count和limit实现

<code>$User = M('User'); // 实例化User对象$count      = $User->where('status=1')->count();// 查询满足要求的总记录数$Page       = new \Think\Page($count,25);// 实例化分页类 传入总记录数和每页显示的记录数(25)$show       = $Page->show();// 分页显示输出// 进行分页数据查询 注意limit方法的参数要使用Page类的属性$list = $User->where('status=1')->order('create_time')->limit($Page->firstRow.','.$Page->listRows)->select();$this->assign('list',$list);// 赋值数据集$this->assign('page',$show);// 赋值分页输出$this->display(); // 输出模板</code>

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php多表查询再加分页的实现求大牛看看
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址