TP5 where多条件查询,组合查询(不等于,模糊查询等)

Think PHP运算符 与 SQL运算符 对照表
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
likelike$whereArr<'username'> = array('like','Admin%');username like 'Admin%'
betweenbetween and$whereArr['id'] = array('between','1,8');id BETWEEN 1 AND 8
not betweennot between and$whereArr['id'] = array('not between','1,8');id NOT BETWEEN 1 AND 8
inin$whereArr['id'] = array('in','1,5,8');id in(1,5,8)
not innot 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)
oror$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();

  • 7
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值