Home > Backend Development > PHP Tutorial > Detailed explanation of how to use limit() in ThinkPHP, thinkphplimit_PHP tutorial

Detailed explanation of how to use limit() in ThinkPHP, thinkphplimit_PHP tutorial

WBOY
Release: 2016-07-12 08:53:46
Original
1108 people have browsed it

Detailed explanation of how to use limit() in ThinkPHP, thinkphplimit

This article introduces the usage of ThinkPHP’s limit() method. The limit method can be used to obtain the number of items in a specified range from the results of database operations. That is equivalent to the limit clause in the mysql query statement.

The

limit method is also one of the coherent operation methods of the model class. It is mainly used to specify the number of queries and operations, especially when paging queries. ThinkPHP l

The imit method is compatible with all database driver classes.

Usage 1. Limit the number of results

For example, to get 10 users who meet the requirements, call the following:

 $User = M('User');
  $User->where('status=1')->field('id,name')->limit(10)->select();
Copy after login
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'));
Copy after login

Usage 2. Paging query

is used for article paging query where the limit method is more commonly used, for example:

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

means querying article data, 25 pieces of data starting from row 10 (it may also depend on the impact of where conditions and limit sorting, not to mention this for now).

After version 3.1, you can also use it like this:

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

For large data tables, try to use limit to limit query results, otherwise it will cause large memory overhead and performance problems.

This is all about how to use limit() in ThinkPHP. I hope it will be helpful to you. At the same time, I also thank you very much for your support of the Bangkejia website!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1122898.htmlTechArticleDetailed explanation of how to use limit() in ThinkPHP, thinkphplimit This article introduces the usage of ThinkPHP's limit() method. The limit method can be used to obtain the number of items in a specified range from the results of database operations. ...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template