ThinkPHP Use Heart Score Sharing Paging Page Usage

  • 2021-06-28 11:29:14
  • OfStack

The Page class in ThinkPHP is in ThinkPHP/Extend/Library/ORG/Util/Page.class.php, so the Page class is introduced before use:


import('ORG.Util.Page'); //Page Introduction of Classes 
$db = M('abc');// Instantiate Data Table abc
$where = array(
'id'=>'2';
);// Conditional statement $where, Field in Sample Table id The value of 2
$count = $db->where($where)->count();// Get the total number of eligible data count
$page = new Page($count, 10);// instantiation page Class, total incoming data and display per page 10 Item Content 
$limit = $page->firstRow . ',' . $page->listRows;// Number and content of data per page $limit
$result =$db->where($where))->limit($limit)->select();// Paging Query Results 
$this->result = $result;// assignment 
$this->show = $page->show();// Get bottom information for paging 

The above code is the basic statement implemented by the paging class. Of course, friends who like to use native sql statements can also use native sql statements to achieve query paging:


        import('ORG.Util.Page'); //Page Introduction of Classes 
        $db = M('abc');// Instantiate Data Table abc
        $where = array(
           'id'=>'2';
        );// Conditional statement $where, Field in Sample Table id The value of 2
        $count = $db->where($where)->count();// Get the total number of eligible data count
        $page = new Page($count, 10);// instantiation page Class, total incoming data and display per page 10 Item Content 
        $Modle = new Model();// Instantiate a new data model 
        $sql = 'select id,name from abc where '.$where.' limit '.$page->firstRow.','.$page->listRows;//sql Sentence 
        $result = $Modle->query($sql);// implement sql Sentence 
        $this->result = $result
        $this->show=$page->show();

Of course, distributing what a query gets can also process the queried data before assigning values, such as


     ...
    $result =$db->where($where))->limit($limit)->select();// Paging Query Results 
    $res = abc($result);//abc Method ( Custom method or php function ) For results $result Sort or reorganize data, etc. 
    $this->result = $res;// assignment 


Related articles: