thinkphp多条件查询(AND, OR)
2017-10-24 17:47
465 查看
SELECT * FROM `ecs_order_info` WHERE
( ( `order_status` = 5 AND `shipping_status` = 2 ) OR `order_status` = 6 ) AND `user_id` = 1
上面标红的where查询语句在TP中的拼接如下:
$order=M('order_info');
$where['order_status']=5;
$where['shipping_status']=2;
$map['_complex'] = $where;
$map['order_status']=6;
$map['_logic'] = 'or';
$final['_complex'] = $map;
$final['user_id']=1;
然后直接查询就可以了: $order->where($final)->select();
问题来了,怎么检测我们写的sql语句没有错呢?执行下面这条语句就可以了,只会翻译成sql语句,不会执行。
echo $order->where($final)->fetchSql(true)->select();
转自:http://blog.csdn.net/landylxy/article/details/70139841
( ( `order_status` = 5 AND `shipping_status` = 2 ) OR `order_status` = 6 ) AND `user_id` = 1
上面标红的where查询语句在TP中的拼接如下:
$order=M('order_info');
$where['order_status']=5;
$where['shipping_status']=2;
$map['_complex'] = $where;
$map['order_status']=6;
$map['_logic'] = 'or';
$final['_complex'] = $map;
$final['user_id']=1;
然后直接查询就可以了: $order->where($final)->select();
问题来了,怎么检测我们写的sql语句没有错呢?执行下面这条语句就可以了,只会翻译成sql语句,不会执行。
echo $order->where($final)->fetchSql(true)->select();
转自:http://blog.csdn.net/landylxy/article/details/70139841
相关文章推荐
- Thinkphp 查询条件 and 和 or同时使用即复合查询
- Thinkphp 查询条件 and 和 or同时使用即复合查询
- thinkphp框架中查询条件or和and搭配问题
- Thinkphp 查询条件 and 和 or同时使用即复合查询
- 将不确定变为确定~表达式树是否可以有个集合,条件过滤有了新方向续(新增了OR和AND查询)
- [thinkphp3.2]多查询语句拼接(And、Or)
- 联合两个索引查询,已解决: 还有个进行多条件搜索 and 与 or 的操作
- mysql同时用and和or关联查询条件,并且值包含null所遇到的坑
- mybatis 拼装 and和or 查询条件
- SQL 复合查询条件(AND,OR,NOT)对NULL值的处理
- SQL 复合查询条件(AND,OR,NOT)对NULL值的处理方法
- SQL 复合查询条件(AND,OR,NOT)对NULL值的处理方法
- Lucene进阶:and 和or的条件查询
- Lucene进阶:and 和or的条件查询
- SQLServer复合查询条件(AND,OR,NOT)对NULL值的处理方法
- mongo java中and、or多条件查询
- thinkphp复合查询AND和OR同时使用
- Elasticsearch进行and,or多条件组合DSL结构化查询
- mongo查询过滤条件java实例($and,$or,$eq,$ne)
- DetachedCriteria多条件查询or,disjunction