首页 > Web开发 > 详细

thinkphp 快捷查询

时间:2019-11-07 12:15:18      阅读:69      评论:0      收藏:0      [点我收藏+]

快捷查询方式是一种多字段查询的简化写法,可以进一步简化查询条件的写法,在多个字段之间用|分割表示OR查询,用&分割表示AND查询,可以实现下面的查询,例如:

大理石平台价格

一、不同字段相同的查询条件

  1. $User = M("User"); // 实例化User对象
  2. $map[‘name|title‘] = ‘thinkphp‘;
  3. // 把查询条件传入查询方法
  4. $User->where($map)->select();

上面的查询其实可以等效于

  1. $User = M("User"); // 实例化User对象
  2. $map[‘name‘] = ‘thinkphp‘;
  3. $map[‘title‘] = ‘thinkphp‘;
  4. $map[‘_logic‘] = ‘OR‘;
  5. // 把查询条件传入查询方法
  6. $User->where($map)->select();

查询条件就变成 name= ‘thinkphp‘ OR title = ‘thinkphp‘

二、不同字段不同的查询条件

  1. $User = M("User"); // 实例化User对象
  2. $map[‘status&title‘] =array(‘1‘,‘thinkphp‘,‘_multi‘=>true);
  3. // 把查询条件传入查询方法
  4. $User->where($map)->select();

上面的查询等效于:

  1. $User = M("User"); // 实例化User对象
  2. $map[‘status‘] = 1;
  3. $map[‘title‘] = ‘thinkphp‘;
  4. // 把查询条件传入查询方法
  5. $User->where($map)->select();

‘_multi‘=>true必须加在数组的最后,表示当前是多条件匹配,这样查询条件就变成 status= 1 AND title = ‘thinkphp‘

,查询字段支持更多的,例如:

  1. $map[‘status&score&title‘] =array(‘1‘,array(‘gt‘,‘0‘),‘thinkphp‘,‘_multi‘=>true);

等效于:

  1. $map[‘status‘] = 1;
  2. $map[‘score‘] = array(‘gt‘,0);
  3. $map[‘title‘] = ‘thinkphp‘;

查询条件就变成 status= 1 AND score >0 AND title = ‘thinkphp‘

注意:快捷查询方式中“|”和“&”不能同时使用。

thinkphp 快捷查询

原文:https://www.cnblogs.com/furuihua/p/11811151.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!