用phpcms v9开发网页用到分页的时候,发现没有多表查询的分页,经过查询资料和看网友的帖子,加上自己的实验,实现了多表关联查询结果的分页效果
文件:model.class.php
final public function mylistinfo($where = '',$countWhere, $page = 1, $pagesize = 10, $key='', $setpages = 10,$urlrule = '',$array = array()) {
// $where = to_sqls($where);
$this->number = $this->count($countWhere);
$page = max(intval($page), 1);
$offset = $pagesize*($page-1);
$this->pages = pages($this->number, $page, $pagesize, $urlrule, $array, $setpages);
$array = array();
if ($this->number > 0) {
//$where.' LIMIT '.$offset.','.$pagesize
//$result = $this->query($where, "$offset, $pagesize");
$result = $this->query($where.' LIMIT '.$offset.','.$pagesize);
return $this->fetch_array();
} else {
return array();
}
}
前台调用:
$page = isset($_GET['page']) && trim($_GET['page']) ? intval($_GET['page']) : 1;
$sql = "SELECT A.NO,A.AREANAME,concat(A.AREANO,'(',B.BEGINTIME,'-',B.ENDTIME,')') AS AREANO,A.USERID,A.EVENTTIME,A.BOOKDATE,A.AREASTATUS FROM b6_book A,b6_subarea B where A.AREANO=B.AREANO AND A.USERID='".$memberinfo['userid']."' AND BOOKDATE>='".date('Y-m-d')."' ORDER BY BOOKDATE";
$booklist = $this->book_db->mylistinfo($sql,"userid ='".$memberinfo['userid']."' and bookdate>='".date('Y-m-d')."'",$page);
$pages = $this->book_db->pages;