The Page class in ThinkPHP is in ThinkPHP/Extend/Library/ORG/Util/Page.class.php, so the Page class must be introduced before use:
Copy code The code is as follows:
import('ORG.Util.Page'); //Introduction of Page class
$db = M('abc');//Instantiated 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 conditions count
$page = new Page($count, 10);//Instantiate the page class, pass in the total number of data and display 10 pieces of content per page
$limit = $page->firstRow . ',' . $page->listRows; //The 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 the bottom information of the paging
The above code is the basic statement for the paging class implementation. Of course, friends who like to use native sql statements can also use native sql statements to implement query paging:
Copy code The code is as follows:
import('ORG.Util.Page'); //Introduction of Page class $count = $db->where($where)->count();//Get the total number of data that meets the conditions count
$page = new Page($count, 10);//Instantiate the page class, pass in the total number of data and display 10 pieces of content per page
$Modle = new Model();//Instantiate the new data model
$sql = 'Select ID, name from abc where'. $ when. 'Limit'. $ pay- & gt; firstRow. ','. $ page- & gt; listRows; // SQL statement
T; query($sql);//Execute sql statement
using sql using sql statement. >
Of course, the content obtained by distributed query can also be processed first and then assigned a value, such as
Copy code
The code is as follows:
...
$result =$db->where($where))->limit($limit)->select();//Paging query results $res = abc($result);/ /abc method (custom method or php function) performs data sorting or reorganization processing on the result $result $this->result = $res;//Assignment
http://www.bkjia.com/PHPjc/770585.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/770585.html
TechArticleThe Page class in ThinkPHP is in ThinkPHP/Extend/Library/ORG/Util/Page.class.php, so Page class must be imported before use: Copy the code as follows: import('ORG.Util.Page'); //Introduction of Page class...
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn