The thinkphp model filters query Fields. the expression method uses the query expression to query the expressions. & #26684; formula: $ map ['Field name'] & nbsp; & nbsp ;=& nbsp; array ('expression', & nbsp; 'query condition'); the expression is case-insensitive and supports the following types of query expressions, which indicate: EQ: equals (= thinkphp model filter query field, expression method
Use a query expression
Query expression format:
$ Map ['Field name'] = Array ('Expression','Query conditions');
The expressions are case-insensitive and support the following query expressions:
EQ: Equal to (=)
Example: $ map ['id'] = array ('EQ ', 100 );
It is equivalent to the following query:
$ Map ['id'] = 100;
The query condition is id = 100.
NEQ: Not equal (! =)
Example: $ map ['id'] = array ('neq', 100 );
The query condition is id! = 100
GT: Greater than (>)
Example: $ map ['id'] = array ('GT ', 100 );
Indicates that the query condition is id> 100.
EGT: Greater than or equal to (> =)
Example: $ map ['id'] = array ('egt', 100 );
The query condition is id> = 100.
LT: Less than (<)
Example: $ map ['id'] = array ('Lt ', 100 );
The query condition is id <100
ELT: Less than or equal to (<=)
Example: $ map ['id'] = array ('elt', 100 );
The query condition is id <= 100
LIKE: LIKE
Example: $ map ['name'] = array ('like', 'thinkphp % ');
The query condition becomes name like 'thinkphp %'
If
DB_LIKE_FIELDSIf the parameter is specified, some fields are automatically fuzzy queried. For example:
'Db _ LIKE_FIELDS '=> 'Title | content'
Use
$ Map ['title'] = 'thinkphp ';
The query condition will change to name like '% thinkphp %'
[NOT]: Same as SQL [not] between, query conditions support strings or arrays, for example:
$ Map ['id'] = array ('between', '1, 8 ');
It is equivalent to the following:
$ Map ['id'] = array ('between', array ('1', '8 '));
The query condition becomes id BETWEEN 1 AND 8.
[NOT] IN: Same as SQL [not] in, query conditions support strings or arrays, for example:
$ Map ['id'] = array ('not in', '1, 5, 8 ');
It is equivalent to the following:
$ Map ['id'] = array ('not in', array ('1', '5', '8 '));
The query condition becomes id not in (, 8)
EXP: Expression, supporting more complex queries
For example:
$ Map ['id'] = array ('in', '1, 3, 8 ');
You can change it:
$ Map ['id'] = array ('Exp ', 'In (1, 3, 8 )');
Exp query conditions are not treated as strings, so the following query conditions can be used
Any syntax supported by SQL, including using functions and field names. A query expression can be used not only for query conditions, but also for data updates. for example:
$ User = M ("User"); // instantiate the User object
// Assign values to the attributes of the data object to be modified
$ Data ['name'] = 'thinkphp ';
$ Data ['score '] = array ('Exp', 'Score + 1'); // add 1 to your credit
$ User-> where ('Id = 5')-> save ($ data); // save the modified data according to the conditions.
The above filter query conditions can be written in the _ filter () function, for example:
// Filter query fields
Function _ filter (& $ map ){
$ Map ['title'] = array ('like', "%". $ _ POST ['til ']. "% ");
$ Map ['categoryid'] = array ('EQ ', $ _ REQUEST ['CID']);
}