码迷,mamicode.com
首页 > 数据库 > 详细

sql分页

时间:2014-12-15 10:24:21      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:des   io   ar   on   cti   ef   as   时间   sql   

private function FnhumanStaffManage($files=Array(),$wherestr="",$page=1){
$Arr = Array();

$page = $this->CHINT($page);
if($page<=0) $page = 1;

$sqlstr = " from human";
$sqlstr.= " left join human_user on human.tid=human_user.hid";
$sqlstr.= " left join human_house on human.tid = human_house.hid";
$sqlstr.= " left join human_signup on human.tid=human_signup.hid";
$sqlstr.= " left join human_tickets on human.tid=human_tickets.hid";
$sqlstr.= " left join human_call on human.tid=human_call.hid";
$sqlstr.= " left join human_vip on human.tid=human_vip.hid";
$sqlstr.= " where human.vuse=1 and human.vdel=1";
$sqlstr.= " and human_user.vuse=1";
$sqlstr.= " and human_user.vdel=1";
$sqlstr.= " and human_user.phone<>‘‘";
$sqlstr.= " ".$wherestr;
$sqlstr.= " order by "
. "human.call_back desc," // 回话时间
. "human_call.itime desc," // 最后一次通话
. "human.itime desc"; // 加入时间

$pages = $this->dbVal("select count(*) from (select tid from (select human.tid ".$sqlstr.") AS KKKKKKKKKK group by tid) AS XXXXXXXXXXX");
$pages = ceil($pages / 50);

$manageSql = "select * from (select human.tid";
$manageSql.= ",human.call_back AS order_human_call_back";
$manageSql.= ",human_call.itime AS order_human_call_itime";
$manageSql.= ",human.itime AS order_human_itime";
$manageSql.= $files;
$manageSql.= $sqlstr;
$manageSql.= ") AS KKKKKKKKKK";

$manageSql.= " group by tid";
$manageSql.= " order by "
. "order_human_call_back desc," // 回话时间
. "order_human_call_itime," // 最后一次通话
. "order_human_itime desc"; // 加入时间

$manageSql.= " limit ".(($page-1)*50).",50";

$list = $this->select($manageSql);

return Array(
"list" => $list,
"pages" => $pages
);
}

sql分页

标签:des   io   ar   on   cti   ef   as   时间   sql   

原文地址:http://www.cnblogs.com/zc39765547/p/4164196.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!