Go thinkphp use of experience sharing-page class page usage

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.