phpcms 多表查询分页

phpcms 多表查询分页,今天放在这里和大家一起分享下。这个函数写在mode.class.php里面,可能不利于升级。直接看代码吧

/**根据SQL查询多表数据并分页,用于多表查询
 * @param $sql
 * @param $order
 * @param $page
 * @param $pagesize
 * @return unknown_type
 */
final public function  mutlilistinfo($sql = '', $page = 1, $pagesize = 20, $key='', $setpages = 10,$urlrule = '',$array = array()){
$sql = preg_replace('/select([^from].*)from/i', "SELECT COUNT(*) as count FROM ", $sql);
$this->query($sql);
$count = $this->db->fetch_next();
$this->number = $count['count'];
$page = max(intval($page), 1);
$offset = $pagesize*($page-1);
$this->pages = pages($this->number, $page, $pagesize, $urlrule, $array, $setpages);
$r = $this->query($where.' LIMIT '.$offset.','.$pagesize);
  $data=new Array();
while(($row = $this->db->fetch_next()) != false){
            $data[] = $row;
    }
return $data;
}

本文由程序员人生www.wfuyu.com整理发布

你可能感兴趣的:(PHP开源)