<?php
/**
* Created by PhpStorm.
* User: Sudo
* Date: 2017/7/11
* Time: 20:22
*/
(一)模糊查询的多字段之间关系为ADN
public function findWithInput(){
$SellerLocation = D('SellerLocation');
$input = I('input');
if (!$input){
$this->ajaxReturn(array('result'=>'false','data'=>'Unable to get your input parameters'),'JSON');//无法获取用户输入参数
}else {
//多字段之间是AND关系
$where['store_name & street & province & city & county & town & specific_address'] = array('like',"%$input%");
$list = $SellerLocation->where($where)->fetchSql(true)->select();//只返回SQL语句,并不进行真实查询
//生成SQL语句为:SELECT * FROM `maigade_seller_location` WHERE ( (`store_name` LIKE '%1219%') AND (`street` LIKE '%1219%') AND (`province` LIKE '%1219%') AND (`city` LIKE '%1219%') AND (`county` LIKE '%1219%') AND (`town` LIKE '%1219%') AND (`specific_address` LIKE '%1219%') )
if ($list!=null){
$this->ajaxReturn(array('result'=>'success','data'=>$list),'JSON');
}elseif($list==null){
$this->ajaxReturn(array('result'=>'false','data'=>'According to the information you have entered is not found in the vicinity of the shop'),'JSON');
}else{
$this->ajaxReturn(array('result'=>'false','data'=>'Select store error'),'JSON');
}
}
}
(二)模糊查询的多字段之间关系为OR
public function findWithInput(){
$SellerLocation = D('SellerLocation');
$input = I('input');
if (!$input){
$this->ajaxReturn(array('result'=>'false','data'=>'Unable to get your input parameters'),'JSON');//无法获取用户输入参数
}else {
//多字段之间是OR关系
$where['store_name | street | province | city | county | town | specific_address'] = array('like',"%$input%");
$list = $SellerLocation->where($where)->fetchSql(true)->select();//只返回SQL语句,并不进行真实查询
//生成SQL语句为:SELECT * FROM `maigade_seller_location` WHERE ( `store_name` LIKE '%1219%' OR `street` LIKE '%1219%' OR `province` LIKE '%1219%' OR `city` LIKE '%1219%' OR `county` LIKE '%1219%' OR `town` LIKE '%1219%' OR `specific_address` LIKE '%1219%' )
if ($list!=null){
$this->ajaxReturn(array('result'=>'success','data'=>$list),'JSON');
}elseif($list==null){
$this->ajaxReturn(array('result'=>'false','data'=>'According to the information you have entered is not found in the vicinity of the shop'),'JSON');
}else{
$this->ajaxReturn(array('result'=>'false','data'=>'Select store error'),'JSON');
}
}
}
?>
ThinkPHP多字段匹配模糊查询
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- mysql 多表关联查询 实现 全文匹配的 模糊搜索接口 SQL mysql中FIND_IN_SET的使用方法 ...
- MySQL提供标准的SQL模式匹配,以及一种基于象Unix实用程序如vi、grep和sed的扩展正则表达式模式匹配...