phpcms v9后台多表查询分页代码
phpcms v9里面自带的listinfo分页函数蛮好用的,可惜啊。不支持多表查询并分页。
看了一下前台模板层支持get标签,支持多表查询,支持分页。刚好可以把这个功能搬到后台来使用。
我们现在对get_model.class.php进行改造使他能支持多表查询并分页。
<?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.html
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。