PHPCMS v9 Background Multi-table query paging code

Source: Internet
Author: User

Phpcms v9 inside the Listinfo function is very good, unfortunately AH. Multiple table queries are not supported and paged.

Look at it. The foreground template layer supports get tags, supports multiple table queries, and supports paging. This function can be moved to the backstage to use.

We are now transforming the get_model.class.php so that he can support multiple table queries and pagination.

<?PHPdefined(' In_phpcms ') orExit(' No permission resources. '));p c_base:: Load_sys_class (' model ', ', 0);classGet_modelextendsModel { 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 functionSql_query ($sql) {        if(!Empty($this->db_tablepre))$sql=Str_replace(' Phpcms_ ',$this->db_tablepre,$sql); returnParent::query ($sql); }         Public functionFetch_next () {return $this->db->Fetch_next (); }    //Custom Paging Query {supports multiple tables}     Public functionMylistinfo ($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; }}?>

How to use:

$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 Background Multi-table query paging code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.