Usage 1, limit the number of results
For example, to get 10 users to meet the requirements, the following call can be:
$User?=?M('User');$User->where('status=1')->field('id,name')->. limit(10)->select();
The limit method can also be used for write operations, such as updating 3 pieces of data that meet the requirements:
$User?=?M('User');$User->where('score=100')->limit(3)-> ;save(array('level'=>'A'));
Usage two, paging query
For article paging query is the limit method is more commonly used occasions, for example:
$Article?=?M('Article');$Article->limit(' 10,25')->select();
Indicates a query for the article data, starting at row 10 of the 25 data (may also depend on the where condition and the impact of the limit ordering This will be left aside for now).
After version 3.1, you can also use it like this:
$Article?=?M('Article');$Article->limit(10,25)->select();
For large data tables, try to limit the query result using limit, otherwise it will lead to a significant memory overhead and performance issues.