One method is a coherent limit operation method model classes

One method of operation limit the number of consecutive model class method is mainly used to specify the query and operations, especially when pagination queries use more. ThinkPHP the limit of the method is compatible with all database-driven class.

Limit the number of results

Such as access to meet the requirements of the user 10, can be the following call:

  1. $User = M('User');
  2. $User->where('status=1')->field('id,name')->limit(10)->select();

The method may also be used to limit write operations, such as updating data satisfies three requirements:

  1. $User = M('User');
  2. $User->where('score=100')->limit(3)->save(array('level'=>'A'));

Paging query

Article pagination query is used to limit the method more commonly used applications, such as:

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

Article indicates that the query data, starting from the line 10 25 data (where conditions may also depend on the impact of this sort and order aside).

In version 3.1, you can use:

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

For large tables, try to limit the query results using the limit, otherwise it will lead to a lot of memory overhead and performance issues.

Marble slab factory

Guess you like