ThinkPHP usage tips-usage of pagination pages

Source: Internet
Author: User
The Page class in ThinkPHP can easily implement querying content pages. This article summarizes the usage of the Page class in the learning process. ThinkPHP

The Page class in ThinkPHP is in ThinkPHP/Extend/Library/ORG/Util/Page. class. php. Therefore, the Page class should be introduced before use:

The code is as follows:
Import ('org. Util. page'); // introduces the Page class.
$ Db = M ('ABC'); // instantiate the data table abc
$ Where = array (
'Id' => '2 ';
); // Condition statement $ where. The value of the field id in the example table is 2.
$ Count = $ db-> where ($ where)-> count (); // obtain the total number of qualified data count
$ Page = new Page ($ count, 10); // instantiate the page class. The total number of incoming data records and 10 entries per page are displayed.
$ Limit = $ page-> firstRow. ','. $ page-> listRows; // The number of data and content on each page $ limit
$ Result = $ db-> where ($ where)-> limit ($ limit)-> select (); // query results by page
$ This-> result = $ result; // value assignment
$ This-> show = $ page-> show (); // Obtain the bottom information of the page.

The above code is a basic statement for paging implementation. of course, friends who prefer native SQL statements can also use native SQL statements to query pages:

The code is as follows:
Import ('org. Util. page'); // introduces the Page class.
$ Db = M ('ABC'); // instantiate the data table abc
$ Where = array (
'Id' => '2 ';
); // Condition statement $ where. The value of the field id in the example table is 2.
$ Count = $ db-> where ($ where)-> count (); // obtain the total number of qualified data count
$ Page = new Page ($ count, 10); // instantiate the page class. The total number of incoming data records and 10 entries per page are displayed.
$ Modle = new Model (); // instance new data Model
$ SQL = 'SELECT id, name from abc where '. $ where. 'limit'. $ page-> firstRow.', '. $ page-> listRows; // SQL statement
$ Result = $ Modle-> query ($ SQL); // execute an SQL statement
$ This-> result = $ result
$ This-> show = $ page-> show ();

Of course, you can process the queried data before assigning values to the content obtained by the Distributed query. for example

The code is as follows:
...

$ Result = $ db-> where ($ where)-> limit ($ limit)-> select (); // query results by page
$ Res = abc ($ result); // The abc method (custom method or php function) sorts or restructured the result $ result.
$ This-> result = $ res; // value assignment

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.