phpcms v9後臺多表查詢分頁代碼

phpcms v9裏面自帶的listinfo分頁函數蠻好用的,惋惜啊。不支持多表查詢並分頁。php

看了一下前臺模板層支持get標籤,支持多表查詢,支持分頁。恰好能夠把這個功能搬到後臺來使用。html

咱們如今對get_model.class.php進行改造使他能支持多表查詢並分頁。sql

<?php defined('IN_PHPCMS') or exit('No permission resources.'); pc_base::load_sys_class('model', '', 0); class get_model extends model { public $db_config, $db_setting; public function __construct($db_config = array(), $db_setting = '') { if (!$db_config) { $this->db_config = pc_base::load_config('database'); } else { $this->db_config = $db_config; } if (!$db_setting) { $this->db_setting = 'default'; } else { $this->db_setting = $db_setting; } parent::__construct(); if ($db_setting && $db_config[$db_setting]['db_tablepre']) { $this->db_tablepre = $db_config[$db_setting]['db_tablepre']; } } public function sql_query($sql) { if (!empty($this->db_tablepre)) $sql = str_replace('phpcms_', $this->db_tablepre, $sql); return parent::query($sql); } public function fetch_next() { return $this->db->fetch_next(); } //自定義分頁查詢{支持多表}
    public function mylistinfo($where = '', $page = 1, $pagesize = 20, $key='', $setpages = 10,$urlrule = '',$array = array()) { $sql = preg_replace('/select([^from].*)from/i', "SELECT COUNT(*) as count FROM ", $where); $this->sql_query($sql); $c = $this->fetch_next(); $this->number = $c['count']; $page = max(intval($page), 1); $offset = $pagesize*($page-1); $this->pages = pages($this->number, $page, $pagesize, $urlrule, $array, $setpages); $r = $this->sql_query($where.' LIMIT '.$offset.','.$pagesize); while(($s = $this->fetch_next()) != false){ $data[] = $s; } return $data; } } ?>

使用方法:函數

$this->get_db = pc_base::load_model('get_model'); $page = intval($_GET['page']); $infos = $this->get_db->mylistinfo($where,$page); $pages = $this->get_db->pages;

 http://www.chanyinkeji.com/phpcms-jiaocheng/10.htmlfetch

相關文章
相關標籤/搜索