您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

thinkPHP实现多字段模糊匹配查询的方法

2025/1/22 3:19:51发布20次查看
这篇文章主要介绍了thinkphp实现多字段模糊匹配查询的方法,结合实例形式分析了thinkphp进行模糊匹配查询的相关模型操作与sql语句,需要的朋友可以参考下
本文实例讲述了thinkphp实现多字段模糊匹配查询的方法。分享给大家供大家参考,具体如下:
引言:有时候查询要匹配多个字段。比如查询地址,地址是由多个字段组成的。有省、市、区等等,以及详细地址。这个时候如何查询呢?
实现不同字段相同的查询条件
$user = m("user"); // 实例化user对象 $map['name|title'] = 'thinkphp'; // 把查询条件传入查询方法 $user->where($map)->select();
用到项目中
if ($address) { // 地址查询 $where['b.province|b.city|b.area|b.detail'] = array('like', '%'.$address.'%'); $this->assign('address', $address); }
这里就很简单的解决了这个需求,而且很精准。
生成的sql语句如下
select a.*,b.name,b.tel,b.province,b.city,b.area,b.detail,b.zipcode from sh_order a left join sh_member_address b on a.member_id = b.member_id and b.selected = 1 where ( `store_id` = '10' ) and ( a.member_id in ('7') ) and ( (b.province like '%宿城区%') or (b.city like '%宿城区%') or (b.area like '%宿城区%') or (b.detail like '%宿城区%') ) order by addtime desc, sendtime asc, paytime desc limit 0,10
从sql语句中可以看出,where中的括号,and,or组合的很巧妙。
截图如下
相关推荐:
框架thinkphp5 简单的实现行为 钩子 hook
以上就是thinkphp实现多字段模糊匹配查询的方法的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product