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!