The implementation of PHP multi-table query plus pagination look, Daniel.

Source: Internet
Author: User
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();    }

Using the TP framework SQL how to page, such as a page display 5 data How to do it

Reply content:

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();    }

Using the TP framework SQL how to page, such as a page display 5 data How to do it

Implemented with count and limit

$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(); // 输出模板
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.