_php example of limit () using method in thinkphp

Source: Internet
Author: User

This article describes the use of the limit () method of thinkphp. The limit method can be used to fetch the number of bars of a specified range for the results of a database operation. That is equivalent to the limit clause in the MySQL query statement.

The Limit method is also one of the consistent operations of model classes, mainly used to specify the number of queries and operations, especially when paging queries are used more often. Thinkphp's L

The Imit method can be compatible with all database-driven classes.

Use one, limit the number of results

For example, to get 10 users who meet the requirements, such as the reduction of the use can:

 $User = M (' User ');
  $User->where (' Status=1 ')->field (' Id,name ')->limit ()->select ();

The limit method can also be used for write operations, such as updating 3 data that meets the requirements:

  $User = M (' User ');
  $User->where (' score=100 ')->limit (3)->save (Array (' Level ' => ' A '));

Usage two, paging query

For article paging query is a common occasion for limit methods, such as:

  $Article = M (' Article ');
  $Article->limit (' 10,25 ')->select ();

Represents querying the article data, 25 data starting at line 10th (which may also depend on the impact of the Where condition and the limit ordering).

After the 3.1 version, you can also use this:

  $Article = M (' Article ');
  $Article->limit (10,25)->select ();

For large data tables, it is possible to use limit to limit query results, which can cause significant memory overhead and performance problems.

About the use of thinkphp limit () to introduce you so much, I hope to help you, but also thank you very much for the cloud Habitat Community website support!

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.