当前位置:K88软件开发文章中心编程语言PHPPHP01 → 文章内容

thinkphp中and和or查询语句的写法

减小字体 增大字体 作者:wangsdong     来源:asp编程网  发布时间:2018-12-30 6:10:59

这里介绍thinkphp中两种条件and和or语句的写法

1、and条件的写法,它的写法比较简单
     $data['id'] = array('eq',3);
     $data['pid'] = array('eq',10);
     这句表达的意思是
     where id = 3 and pid = 10 这种写法

2、or条件的写法
  or条件的写法要分两种情况
  a、同一字段
     $data['id'] = array(array('eq',3),array('eq',10), 'or') ; 
     这句表达的意思是
     where id = 3 or id = 10 
  b、不同字段
     $where['name']  = array('like', '%K88.NET%');
     $where['title']  = array('like','%K88.NET%');
     $where['_logic'] = 'or';
     $data['_complex'] = $where;   //or条件完成
     $data['id']  = array('gt',1); //其他条件
     这句表达的意思是
     where (name like '%K88.NET%' or title like '%K88.NET%') and id =1;

原创文章,转载请注明来源www.K88.NET,谢谢

thinkphp中and和or查询语句的写法