thinkPHP SQL语句中表达式查询的格式
查询表达式格式:$map['字段名'] = array('表达式','查询条件');
PS:表达式不区分大小写。
例子:
//EQ:等于(=)
$map['id'] = array('eq', 1); //where 为id=1
//NEQ:不等于()
$map['id'] = array('neq', 1); //where 为id1
//GT:大于(>)
$map['id'] = array('gt', 1); //where 为id>1
//EGT:大于等于(>=)
$map['id'] = array('egt', 1); //where 为id>=1
//LT:小于($map['id'] = array('lt', 1); //where 为id//ELT:小于等于($map['id'] = array('elt', 1); //where 为id//[NOT]LIKE:模糊查询
$map['user'] = array('like', '%小%'); //where 为like %小%
//[NOT]LIKE:模糊查询
$map['user'] = array('notlike', '%小%'); //where 为not like %小%
//[NOT]LIKE:模糊查询的数组方式
$map['user'] = array('like', array('%小%', '%蜡%'), 'AND');
//生成的SQL
SELECT * FROM `think_user` WHERE ( (`user` LIKE '%小%' AND `user`
LIKE '%蜡%') )
//[NOT] BETWEEN:区间查询
$map['id'] = array('between','1,3');
//where 为`id` BETWEEN '1' AND '2'
//同上等效
$map['id'] = array('between',array('1','3'));
//[NOT] BETWEEN:区间查询
$map['id'] = array('not between','1,3');
//where 为`id` NOT BETWEEN '1' AND '2'
//[NOT] IN:区间查询
$map['id'] = array('in','1,2,4');
//where 为`id` IN ('1','2','4')
//[NOT] IN:区间查询
$map['id'] = array('not in','1,2,4');
//where 为`id` NOT IN ('1','2','4')
//EXP:自定义
$map['id'] = array('exp','in (1,2,4)');
//where 为`id` NOT IN ('1','2','4')
PS:使用exp 自定义在第二个参数直接写where 语句即可
//EXP:自定义增加OR 语句
$map['id'] = array('exp', '=1');
$map['user'] = array('exp', '="蜡笔小新"');
$map['_logic'] = 'OR';
//WHERE 为( (`id` =1) ) OR ( (`user` ="蜡笔小新") )
上一篇: CSS技巧之CSS中的随机数