thinkphp5,mysql语句用到group by怎么分页
展开全部
$_GET['p'];
if(!$p){
$p = '0';
}else{
$p = $p-1;
$p = $p*20;
}
$limit = '20';
$limits = "limit ".$p.",".$limit;
$where = "`username` LIKE '%".$keywords."%' AND `status` > '-1' AND `num` <> '' AND ".$department_path;
$sql = "SELECT * FROM (SELECT * FROM `sr_member` WHERE ".$where." ORDER BY update_time desc, add_time desc) as a GROUP BY num ORDER BY add_time desc ".$limits;
$sql_count = "SELECT count(*) as count FROM (SELECT * FROM (SELECT * FROM `sr_member` WHERE ".$where." ORDER BY update_time desc, add_time desc) as a GROUP BY num) as temp ";
$member_array = M()->query($sql);
$counts = M()->query($sql_count);
$count = $counts['0']['count'];
// echo $count;exit;
$data ['pages'] = ceil ($count/$limit);
$Page = new \Think\Page ( $count, $limit ); // 实例化分页类 传入总记录数和每页显示的记录数
$Page->setConfig ( 'header', '条数据' ); // 共有多少条数据
$Page->setConfig ( 'prev', "<" ); // 上一页
$Page->setConfig ( 'next', '>' ); // 下一页
$Page->setConfig ( 'first', '首页' ); // 第一页
$Page->setConfig ( 'last', '尾页' ); // 最后一页
$data ['page'] = $Page->show (); // 分页显示输出
if(!$p){
$p = '0';
}else{
$p = $p-1;
$p = $p*20;
}
$limit = '20';
$limits = "limit ".$p.",".$limit;
$where = "`username` LIKE '%".$keywords."%' AND `status` > '-1' AND `num` <> '' AND ".$department_path;
$sql = "SELECT * FROM (SELECT * FROM `sr_member` WHERE ".$where." ORDER BY update_time desc, add_time desc) as a GROUP BY num ORDER BY add_time desc ".$limits;
$sql_count = "SELECT count(*) as count FROM (SELECT * FROM (SELECT * FROM `sr_member` WHERE ".$where." ORDER BY update_time desc, add_time desc) as a GROUP BY num) as temp ";
$member_array = M()->query($sql);
$counts = M()->query($sql_count);
$count = $counts['0']['count'];
// echo $count;exit;
$data ['pages'] = ceil ($count/$limit);
$Page = new \Think\Page ( $count, $limit ); // 实例化分页类 传入总记录数和每页显示的记录数
$Page->setConfig ( 'header', '条数据' ); // 共有多少条数据
$Page->setConfig ( 'prev', "<" ); // 上一页
$Page->setConfig ( 'next', '>' ); // 下一页
$Page->setConfig ( 'first', '首页' ); // 第一页
$Page->setConfig ( 'last', '尾页' ); // 最后一页
$data ['page'] = $Page->show (); // 分页显示输出
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |