thinkphp5.0.1关联查询怎么分页
1个回答
展开全部
public function query_money(){
$m = M();
$where = "1=1";//fanwe_payment_notice.user_id >70000
$count = $m->where($where)->query("SELECT count(*) from fanwe_payment_notice LEFT JOIN fanwe_user on (fanwe_user.id = fanwe_payment_notice.user_id)");
//select u.id,u.user_name,u.mobile,p.notice_sn,p.is_paid,p.money,p.pay_date,p.memo from fanwe_user u , fanwe_payment_notice p where p.user_id = u.id
$p = getpage($count[0]['count(*)'],10);
$sql = "SELECT fanwe_user.id,fanwe_user.user_name,fanwe_user.mobile,fanwe_payment_notice.notice_sn,fanwe_payment_notice.is_paid,fanwe_payment_notice.money,fanwe_payment_notice.pay_date from fanwe_payment_notice LEFT JOIN fanwe_user on (fanwe_user.id = fanwe_payment_notice.user_id)";
$list = $m->field(true)->where($where)->order('id')->limit($p->firstRow, $p->listRows)->query($sql);
$this->assign('page', $p->show()); // 赋值分页输出
$this->assign('list', $list); // 赋值数据集
$this->display();
}
$m = M();
$where = "1=1";//fanwe_payment_notice.user_id >70000
$count = $m->where($where)->query("SELECT count(*) from fanwe_payment_notice LEFT JOIN fanwe_user on (fanwe_user.id = fanwe_payment_notice.user_id)");
//select u.id,u.user_name,u.mobile,p.notice_sn,p.is_paid,p.money,p.pay_date,p.memo from fanwe_user u , fanwe_payment_notice p where p.user_id = u.id
$p = getpage($count[0]['count(*)'],10);
$sql = "SELECT fanwe_user.id,fanwe_user.user_name,fanwe_user.mobile,fanwe_payment_notice.notice_sn,fanwe_payment_notice.is_paid,fanwe_payment_notice.money,fanwe_payment_notice.pay_date from fanwe_payment_notice LEFT JOIN fanwe_user on (fanwe_user.id = fanwe_payment_notice.user_id)";
$list = $m->field(true)->where($where)->order('id')->limit($p->firstRow, $p->listRows)->query($sql);
$this->assign('page', $p->show()); // 赋值分页输出
$this->assign('list', $list); // 赋值数据集
$this->display();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询