Turn the--http://www.jb51.net/article/50138.htm
The page class in thinkphp is in thinkphp/extend/library/org/util/page.class.php, so the page class is introduced before use:
Copy CodeThe code is 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 CodeThe code is 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 CodeThe code is 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
Go thinkphp use of experience sharing-page class page usage