1
我正在使用以下查詢來獲取數據。當我將參數傳遞給where
子句時,它將參數轉換爲問號?
。在將參數傳遞給laravel 5查詢生成器時的子句錯誤
$productDatas = DB::table('products')
->select('products.*','products.id as pid','product_features.*','product_features.id as pfid')
->join('product_features','product_features.product_id','=','products.id')
->join('categories','categories.id','=','products.cat_id','left');
if($value == 13) {
// $value = intval($value);
$productData = $productDatas->where('product_features.'.$field,'<',$value)->toSql();
dd($productData);
} else {
$productData = $productDatas->where('product_features.'.$field,'=',$value)->get();
}
輸出查詢:
"select `products`.*, `products`.`id` as `pid`, `product_features`.*, `product_features`.`id` as `pfid`
from `products`
inner join `product_features` on `product_features`.`product_id` = `products`.`id`
left join `categories` on `categories`.`id` = `products`.`cat_id`
where `product_features`.`primary_camera` < ?"
問題是什麼? –
問題沒有從數據庫獲取實際數據 –
dd($ productData)是幹什麼的?在你的'else'塊中,你正在調用' - > get()'函數,但是你沒有在'if'塊中這樣做。 – akousmata