TP5 where多条件查询,组合查询(不等于,模糊查询等)
ThinkPHP运算符 与 SQL运算符 对照表TP运算符SQL运算符例子实际查询条件eq=$whereArr['id'] = array('eq',100);等效于:$map['id'] = 100;neq!=$whereArr['id'] = array('neq',100);id != 100gt...
·
| TP运算符 | SQL运算符 | 例子 | 实际查询条件 |
|---|---|---|---|
| eq | = | $whereArr['id'] = array('eq',100); | 等效于:$map['id'] = 100; |
| neq | != | $whereArr['id'] = array('neq',100); | id != 100 |
| gt | > | $whereArr['id'] = array('gt',100); | id > 100 |
| egt | >= | $whereArr['id'] = array('egt',100); | id >= 100 |
| lt | < | $whereArr['id'] = array('lt',100); | id < 100 |
| elt | <= | $whereArr['id'] = array('elt',100); | id <= 100 |
| like | like | $whereArr<'username'> = array('like','Admin%'); | username like 'Admin%' |
| between | between and | $whereArr['id'] = array('between','1,8'); | id BETWEEN 1 AND 8 |
| not between | not between and | $whereArr['id'] = array('not between','1,8'); | id NOT BETWEEN 1 AND 8 |
| in | in | $whereArr['id'] = array('in','1,5,8'); | id in(1,5,8) |
| not in | not in | $whereArr['id'] = array('not in','1,5,8'); | id not in(1,5,8) |
| and(默认) | and | $whereArr['id'] = array(array('gt',1),array('lt',10)); | (id > 1) AND (id < 10) |
| or | or | $whereArr['id'] = array(array('gt',3),array('lt',10), 'or'); | (id > 3) OR (id < 10) |
| xor(异或) | xor | 两个输入中只有一个是true时,结果为true,否则为false,例子略。 | 1 xor 1 = 0 |
| exp | 综合表达式 | $whereArr['id'] = array('exp','in(1,3,8)'); | $whereArr['id'] = array('in','1,3,8'); |
根据以上对照表写对应数组条件,组合查询即可。
例如:
$whereArr['id'] = array('neq',1); // 不等于条件
$whereArr['state'] = array('eq',1); // 其他条件
$res = db('user')->filed(*)->where($whereArr)->select();
更多推荐


所有评论(0)