Home Backend Development PHP Tutorial thinkphp model filter query field, expression method_PHP tutorial

thinkphp model filter query field, expression method_PHP tutorial

Jul 13, 2016 pm 05:53 PM
array map thinkphp use Field method condition Inquire Format Model of expression filter

Use query expressions
Query expression usage format:
$map['field name'] = array('expression', 'query condition');
Expressions are not case-sensitive. The supported query expressions are as follows, and their respective meanings are:
EQ: equal to (=)
For example: $map['id'] = array('eq',100);
Equivalent to the following query
$map['id'] = 100;
The query condition represented is id = 100
NEQ: Not equal to (!=)
For example: $map['id'] = array('neq',100);
The query condition represented is id != 100
GT: Greater than (>)
For example: $map['id'] = array('gt',100);
The query condition represented is id > 100
EGT: Greater than or equal to (>=)
For example: $map['id'] = array('egt',100);
The query condition represented is id >= 100
LT: less than (<)
For example: $map['id'] = array('lt',100);
The query condition represented is id < 100
ELT: Less than or equal to (<=)
For example: $map['id'] = array('elt',100);
The query condition represented is id <= 100
LIKE: Same as sql’s LIKE
For example: $map['name'] = array('like','thinkphp%');
The query condition becomes name like 'thinkphp%'
If the DB_LIKE_FIELDS parameter is configured, some fields will also automatically perform fuzzy queries. For example, set:
'DB_LIKE_FIELDS'=>'title|content'
If so, use
$map['title'] = 'thinkphp';
The query condition will become name like '%thinkphp%'
[NOT] BETWEEN: Same as SQL's [not] between, query conditions support strings or arrays, for example:
$map['id'] = array('between','1,8');
Equivalent to:
$map['id'] = array('between',array('1','8'));
The query condition becomes id BETWEEN 1 AND 8
[NOT] IN: Same as SQL's [not] in, query conditions support strings or arrays, for example:
$map['id'] = array('not in','1,5,8');
Equivalent to:
$map['id'] = array('not in',array('1','5','8'));
The query condition becomes id NOT IN (1,5, 8)
EXP: Expression, supports more complex query situations
For example:
$map['id'] = array('in','1,3,8');
Can be changed to:
$map['id'] = array('exp',' IN (1,3,8) ');
The conditions of exp query will not be treated as strings, so subsequent query conditions can use any syntax supported by SQL, including using functions and field names. Query expressions can not only be used for query conditions, but also for data updates, for example:
$User = M("User"); // Instantiate User object
//Assign the data object attributes to be modified
$data['name'] = 'ThinkPHP';
$data['score'] = array('exp','score+1'); // Add 1 to the user's points
$User->where('id=5')->save($data); // Save modified data according to conditions

The above filtering query conditions can be written in the _filter() function, such as:
//Filter query field
Function _filter(&$map){
         $map['title'] = array('like',"%".$_POST['til']."%");
         $map['categoryId'] = array('eq',$_REQUEST['cid']);
                         
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477993.htmlTechArticleUse query expression to query expression usage format: $map[field name] = array(expression, query Condition); The expression is not case-sensitive. The supported query expressions are as follows, listed separately...
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to recover deleted contacts on WeChat (simple tutorial tells you how to recover deleted contacts) How to recover deleted contacts on WeChat (simple tutorial tells you how to recover deleted contacts) May 01, 2024 pm 12:01 PM

How to recover deleted contacts on WeChat (simple tutorial tells you how to recover deleted contacts)

The world's most powerful open source MoE model is here, with Chinese capabilities comparable to GPT-4, and the price is only nearly one percent of GPT-4-Turbo The world's most powerful open source MoE model is here, with Chinese capabilities comparable to GPT-4, and the price is only nearly one percent of GPT-4-Turbo May 07, 2024 pm 04:13 PM

The world's most powerful open source MoE model is here, with Chinese capabilities comparable to GPT-4, and the price is only nearly one percent of GPT-4-Turbo

KAN, which replaces MLP, has been extended to convolution by open source projects KAN, which replaces MLP, has been extended to convolution by open source projects Jun 01, 2024 pm 10:03 PM

KAN, which replaces MLP, has been extended to convolution by open source projects

Hello, electric Atlas! Boston Dynamics robot comes back to life, 180-degree weird moves scare Musk Hello, electric Atlas! Boston Dynamics robot comes back to life, 180-degree weird moves scare Musk Apr 18, 2024 pm 07:58 PM

Hello, electric Atlas! Boston Dynamics robot comes back to life, 180-degree weird moves scare Musk

The secret of hatching mobile dragon eggs is revealed (step by step to teach you how to successfully hatch mobile dragon eggs) The secret of hatching mobile dragon eggs is revealed (step by step to teach you how to successfully hatch mobile dragon eggs) May 04, 2024 pm 06:01 PM

The secret of hatching mobile dragon eggs is revealed (step by step to teach you how to successfully hatch mobile dragon eggs)

How to set font size on mobile phone (easily adjust font size on mobile phone) How to set font size on mobile phone (easily adjust font size on mobile phone) May 07, 2024 pm 03:34 PM

How to set font size on mobile phone (easily adjust font size on mobile phone)

FisheyeDetNet: the first target detection algorithm based on fisheye camera FisheyeDetNet: the first target detection algorithm based on fisheye camera Apr 26, 2024 am 11:37 AM

FisheyeDetNet: the first target detection algorithm based on fisheye camera

BTCC tutorial: How to bind and use MetaMask wallet on BTCC exchange? BTCC tutorial: How to bind and use MetaMask wallet on BTCC exchange? Apr 26, 2024 am 09:40 AM

BTCC tutorial: How to bind and use MetaMask wallet on BTCC exchange?

See all articles