The page class in thinkphp is in thinkphp/extend/library/org/util/page.class.php, so the page class is introduced before use:
Copy the Code code as follows:
Import (' ORG. Util.page '); Introduction of the Page class
$db = M (' abc ');//instantiation of the data table ABC
$where = Array (
' id ' = ' 2 ';
)///Conditional statement $where, the value of the field ID in the example table is 2
$count = $db->where ($where)->count ()//Get the total number of data that meets the criteria count
$page = new Page ($count, 10);//Instantiate the page class, the total number of incoming data and display 10 items per page
$limit = $page->firstrow. ',' . $page->listrows;//number of data per page and content $limit
$result = $db->where ($where))->limit ($limit)->select ();//Paged Query results
$this->result = $result;//Assignment
$this->show = $page->show ();//Get the bottom information of the page
The above code is the basic statement of the implementation of the paging class, and of course, friends who prefer to use native SQL statements can also implement query paging with native SQL statements:
Copy the Code code as follows:
Import (' ORG. Util.page '); Introduction of the Page class
$db = M (' abc ');//instantiation of the data table ABC
$where = Array (
' id ' = ' 2 ';
)///Conditional statement $where, the value of the field ID in the example table is 2
$count = $db->where ($where)->count ()//Get the total number of data that meets the criteria count
$page = new Page ($count, 10);//Instantiate the page class, the total number of incoming data and display 10 items per page
$Modle = new Model ();
$sql = ' Select Id,name from ABC where '. $where. ' Limit ' $page->firstrow. ', '. $page->listrows;//sql Statement
$result = $Modle->query ($sql);//Execute SQL statement
$this->result = $result
$this->show= $page->show ();
Of course, the contents of a distributed query can also be processed and then assigned to the finished data, such as
Copy the Code code as follows:
...
$result = $db->where ($where))->limit ($limit)->select ();//Paged Query results
$res = ABC ($result),//abc method (custom method or PHP function) to sort the result $result data or reorganize the processing, etc.
$this->result = $res;//Assignment
http://www.bkjia.com/PHPjc/770585.html www.bkjia.com true http://www.bkjia.com/PHPjc/770585.html techarticle the page class in thinkphp is in thinkphp/extend/library/org/util/page.class.php, so introduce the page class before use: Copy the code as follows: Import (' ORG. Util.page '); Introduction of the Page class ...