我正試圖在Laravel中執行whereIN
查詢。我想匹配的值是數據庫表中的值,如:「a,b,c,d」如何在Laravel中執行whereIN查詢?
我想選擇上面包含在此字符串中的所有用戶名。 所以我把字符串和爆炸它創建一個數組,然後我將這個數組添加到Laravel命令。問題是,它返回只有一個用戶只匹配字母「a」例如,它停止。
的控制器代碼:
public function returnEorti(){
$month = Input::get('month');
$day = Input::get('day');
$eorti = DB::select("select text from days where day='$day' and month='$month'");
$eortiFinal = explode(",", $eorti[0]->text);
$pelatis = Pelatis::whereIn('Onoma', $eortiFinal)->get();
return json_encode($pelatis);
}
阿賈克斯:
$.ajax({
type:"GET",
url:"getEorti",
data:{"day":d[2],"month":d[1]},
success:function(data){
var b = jQuery.parseJSON(data)
for(var i=0;i<Object.keys(b).length;i++){
$("#test").append(b[i].Onoma+'</br>');
}
console.log(data);
}
});
我的路線:
Route::get('getEorti','[email protected]');
的 'Pelates' 表: 的p_id Onoma Epitheto Onoma_Miteras Onoma_Patera Hmerominia_Gennisis Tilefono_Oikias Kinito_Tilefono Diefthinsi DIMOS Periferia Periferiaki_Enotita Epaggelma 電子郵件
'$ eortiFinal'中的實際值是什麼,以及您期望匹配哪個'Pelatis' db行?這不完全是[SSCCE](http://sscce.org/) – dehrg 2014-08-27 16:40:58
Pelatis是客戶的表... $ eortiFinal是一個數組,它有「a,b,c,d」我之前提到但被''分隔符分解。 – sarakinos 2014-08-27 16:53:30
是的,我意識到Pelatis是一張桌子,桌子上有什麼行? – dehrg 2014-08-27 16:56:01