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

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

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

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


用count和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(); // 输出模板
【热门文章】
【热门文章】