1、写在前面:mysql的分页 通过limit 关键字进行处理, oracle却没有limit,而是用ROWNUM 字段来进行分页
2、参考示例,TP3.2 代码,其实原理看懂了 其他框架和原生都可以使用:
分页page 使用的TP3.2框架自带的,我就是把sql进行了转换,使其符合oracle 分页的格式。
注意:里面的 Dingsql()方法,在上一篇文章里面有,放在common/function.php里面。
public function index($type=1){ //统计要查询数据的数量 $page_size = 10; //评论固定10条 $page = intval($_REQUEST['p']); if(empty($page))$page = 1; //$limit = (($page-1)*$page_size).",".$page_size ; //mysql使用这种,oracle使用下面 //当页码大于1时,每页的开始记录是 (页码-1) * 每页记录数 +1 -- >> 适用于oracle分页 $startRow = ($page - 1) * $page_size + 1; $endRow = $page * $page_size; $select1 = "SELECT JGDA.JGID, JGDA.SNAME, COUNT(DISTINCT SALETIME.KHID) KHQTY, COUNT(DISTINCT SALETIME.KHID || '^' || SALETIME.SALEDATE) RQQTY, RQYD.YAER, RQYD.MONTH, SUM(SALENET) SALENET, SUM(BILLQTY) BILLQTY FROM CSC.SALETIME , CSC.KHDA, CSC.RQYD, CSC.V_JGLEN, CSC.JGDA WHERE SALETIME.KHID = KHDA.KHID AND SUBSTR(KHDA.JGID,1, V_JGLEN.LEN)= JGDA.JGID AND SALETIME.SALEDATE = RQYD.DATE_XG GROUP BY JGDA.JGID, JGDA.SNAME, RQYD.YAER, RQYD.MONTH "; switch ($type){ case 1: $select = $select1; break; default: $select = $select1; break; } $page_sql = "select * from ( select temp.*, ROWNUM rn from (".$select.") temp ) where rn between $startRow and $endRow "; //$sql = $select_count1; $sql = $page_sql; //oracle分页sql $list = DingSql($sql); //一个页面的数据<=$page_size条 //分页 //$count = DingSql($select_count1); $count = DingSql($select); //所有符合条件的数据 $total = count($count); $listRows = C('LIST_ROWS') > 0 ? C('LIST_ROWS') : 10; $REQUEST = (array)I('request.'); //$page = new ThinkPage($total, $listRows, $_REQUEST); $page = new ThinkPage($total, $listRows, $_REQUEST); if($total>$listRows){ $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%'); } $p =$page->show(); $this->assign('_page', $p? $p: ''); $this->assign('_total',$total); //echo "<pre>";var_dump($list); $this->assign('meta_title',$this->meta_title); $this->assign('_list',$list); $this->display(); }
3、效果:
4、总结:刚开始我以为很难,没想到结合起来,其实挺简单的。