The limit method is also one of the coherent operation methods of model classes. it is mainly used to specify the number of queries and operations, especially when querying by page. The limit method of ThinkPHP can be compatible with all database driver classes. The limit method is also one of the coherent operation methods of model classes. it is mainly used to specify the number of queries and operations, especially when querying by page. The limit method of ThinkPHP can be compatible with all database driver classes. Use the following command to limit the number of results, for example, to obtain 10 users that meet the requirements:
- $ User = M ('user ');
- $ User-> where ('status = 1')-> field ('Id, name')-> limit (10)-> select ();
The copy code limit method can also be used for write operations, such as updating three data entries that meet the requirements:
- $ User = M ('user ');
- $ User-> where ('score = 100 ')-> limit (3)-> save (array ('level' => 'A '));
Copying code paging query is a commonly used limit method for article paging query. for example:
- $ Article = M ('article ');
- $ Article-> limit ('10, 25')-> select ();
Copy the code to query the article data. 25 pieces of data starting from row 10th may also be affected by the where condition and order sorting ).
After version 3.1, you can also use:
- $ Article = M ('article ');
- $ Article-> limit (10, 25)-> select ();
For large data tables, use limit to limit query results. otherwise, memory overhead and performance problems may occur.