Use a query expression
Query expression format:
$ Map ['field name'] = array ('expression', 'query condition ');
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: similar to SQL LIKE
Example: $ map ['name'] = array ('like', 'thinkphp % ');
The query condition becomes name like 'thinkphp %'
If the DB_LIKE_FIELDS parameter is configured, 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] BETWEEN: 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 that supports 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 use 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']);
}