The page class in thinkphp is in thinkphp/extend/library/org/util/page.class.php, so you introduce the page class before you use it:
Copy Code code as follows:
Import (' ORG. Util.page '); Introduction of Page Class
$db = M (' abc ');//materialized datasheet 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 eligible data count
$page = new Page ($count, 10);//Instantiate page class, total incoming data and 10 items per page
$limit = $page->firstrow. ',' . $page->listrows;//the number of data and content per page $limit
$result = $db->where ($where))->limit ($limit)->select ()//Paging query results
$this->result = $result;//Assignment
$this->show = $page->show ()//Get the bottom information of pagination
The above code is the basic statement of the Page class implementation, of course, friends like to use native SQL statements can also cooperate with native SQL statements to implement query paging:
Copy Code code as follows:
Import (' ORG. Util.page '); Introduction of Page Class
$db = M (' abc ');//materialized datasheet 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 eligible data count
$page = new Page ($count, 10);//Instantiate page class, total incoming data and 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 data after the query, such as
Copy Code code as follows:
...
$result = $db->where ($where))->limit ($limit)->select ()//Paging query results
$res = ABC ($result);//abc method (custom method or PHP function) to sort or reorganize the result $result
$this->result = $res;//Assignment