2017-07-27 122 views
0
if(!empty($count)){ 
    $BattingQuery->where('countries_id', 'LIKE', '%'.$count.'%'); 
} 

我運行此查詢,但這個產量問題的錯誤,如果我的國家ID 11, 12, 13, 14;運行搜索我總是得到1藏漢作爲11例如country_id。我如何使它成爲Equals?因爲'='和Equals都不返回並且中斷查詢。與LIKE子句

回答

1

查詢生成器有一些非常有用的where clauses

$count = 13; 
if(!empty($count)){ 
    $BattingQuery->where('countries_id', $count); 
} 

這將所有模型返回了countries_id等於13

+0

那不是我想要的。我想要查詢返回與我輸入的確切ID。就像現在一樣,如果您搜索的號碼中包含多個號碼,則會返回多個號碼。 – dionarap

+0

您想要完全匹配嗎?一些可以通過'$ a == $ b'在php中完成的事情? – milo526

+0

yes countries_id ='%'。$ count。'%'。計數是一個輸入選擇。 – dionarap

0

我想你應該試試這個:

if(!empty($count)){ 
    $BattingQuery->orWhere('countries_id', 'like', '%' . $count . '%'); 
} 

希望這對你的工作!