thinkphp 3.2快捷查询OR查询&分割表示AND查询讲解

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

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

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

            $User = M("User"); // 实例化User对象
            $map['name'] = 'thinkphp';
            $map['title'] = 'thinkphp';
            $map['_logic'] = 'OR';
            // 把查询条件传入查询方法
            $User->where($map)->select();

        查询条件就变成 name= 'thinkphp' OR title = 'thinkphp'
        二、不同字段不同的查询条件

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

        上面的查询等效于:

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

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

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

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

        等效于:

            $map['status'] = 1;
            $map['score'] = array('gt',0);
            $map['title'] = 'thinkphp';

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

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

相关文章:

  • 2021-12-07
  • 2021-10-09
  • 2021-10-02
  • 2021-10-24
  • 2022-12-23
  • 2022-03-05
  • 2022-01-18
  • 2021-06-25
猜你喜欢
  • 2021-07-07
  • 2022-12-23
  • 2022-12-23
  • 2021-04-04
  • 2022-12-23
  • 2022-03-07
相关资源
相似解决方案