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

來源:互聯網
上載者:User

標籤:

phpcms v9裡面內建的listinfo分頁函數蠻好用的,可惜啊。不支援多表查詢並分頁。

看了一下前台模板層支援get標籤,支援多表查詢,支援分頁。剛好可以把這個功能搬到後台來使用。

我們現在對get_model.class.php進行改造使他能支援多表查詢並分頁。

<?phpdefined(‘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.html

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.