zoukankan      html  css  js  c++  java
  • Thinkphp 查询条件 and 和 or同时使用即复合查询

      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'

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

  • 相关阅读:
    python 基础到字符串学习
    Newtonsoft.Json 获取匿名类数据
    Abp Wcf结合使用问题
    Ef Migration 操作出现SQLEXPRESS
    No context type was found in the assembly 'xxx.xxxx'. CodeFirst Ef错误
    Ef Code First 发生”provider: SQL Network Interfaces, error: 26
    ef 多条数据插入处理方案(据说还有更好的)
    记录一次 HttpWebRequest 尝试自动重定向太多 错误
    NetCore 下使用RSA加密,解密;并且前端使用jsencrypt.js实现Rsa相关方法。
    The specified framework version '2.0' could not be parsed 错误处理
  • 原文地址:https://www.cnblogs.com/lxwphp/p/9699267.html
Copyright © 2011-2022 走看看