我现在有一个搜索功能在我的网站,我需要它搜索三个领域-应用,移动,电子邮件。
现在,一旦用户在搜索框中输入数据,它就会搜索所有的3个,但不起作用。
使用GET收集数据。
这是我的查询
http://www.example.com?id=1&searchall=07853637362
$mobile = INPUT::get('searchall');
$email = INPUT::get('searchall');
$appid = INPUT::get('searchall');
$data = DB::table('leads')
->when($mobile, function($query) use ($mobile){
return $query->where('MobilePhone', $mobile);
})
->when($email, function($query) use ($email){
return $query->where('Email', $email);
})
->when($appid, function($query) use ($appid){
return $query->where('AppID', $appid);
})
->get();因此,我需要它搜索每个字段,直到找到正确的字段值。
发布于 2017-02-28 12:25:36
$mobile = INPUT::get('searchall');
$email = INPUT::get('searchall');
$appid = INPUT::get('searchall');
$data = DB::table('leads')
->when($mobile, function($query) use ($mobile){
return $query->orWhere('MobilePhone', $mobile);
})
->when($email, function($query) use ($email){
return $query->orWhere('Email', $email);
})
->when($appid, function($query) use ($appid){
return $query->orWhere('AppID', $appid);
})->get();发布于 2017-02-28 12:08:28
使用like搜索数据尝试
->when($mobile, function($query) use ($mobile){
return $query->where('MobilePhone', 'like', '%'. $mobile . '%');
})要实际搜索每个字段,请使用orWhere
$keywords = Input::get('searchall');
$data = DB::table('leads')
->where('mobilephone', '=', $keywords)
->orWhere('email', '=', $keywords)
->orWhere('AppID', '=', $keywords)
->get();发布于 2017-02-28 12:18:17
我不明白为什么您需要使用3个变量从用户那里获得相同的值,所以下面是简化的版本:
$searched = Input::get('searchall');
$matched = DB::table('leads')
->where('MobilePhone', $searched)
->orWhere('Email', $searched)
->orWhere('AppID', $searched)
->get();https://stackoverflow.com/questions/42508235
复制相似问题