【发布时间】:2021-01-10 12:35:37
【问题描述】:
我想使用价格过滤一些数据,但是当我们回显请求值时它给出正确但是当我把它放在查询中时它显示“?”
我的 ajax 调用
<script>
$(document).ready(function() {
$("#price_filter").on("change", function() {
var price = this .value;
var _token = $('input[name="_token"]').val();
$.ajax({
url:"{{ route('indexController.pricefilter') }}",
type:"POST",
dataType:"json",
data:{price,_token},
success: function(response){
console.log(response);
// $("#filterdata").html(response);
}
});
})
})
</script>
我的路线
Route::post('indexController/pricefilter','indexController@pricefilter')->name('indexController.pricefilter');
我的功能
public function pricefilter(Request $request){
echo $price = $request->get('price');
return $products = DB::table('products')
->where('price','=', $price)
->tosql();
}
我的查询结果
400
select * from `products` where `price` = ?
它实际上看起来像
select * from `products` where `price` = 400
这是结果
array:1 [
0 => array:3 [
"query" => "select * from `products` where `price` <= ?"
"bindings" => array:1 [
0 => "1001"
]
"time" => 3.87
]
]
【问题讨论】:
-
检查输出
dd($request->price);,还是空? -
它显示值但查询不使用价格过滤数据它返回所有数据
-
但是当我们把这个
->where('price','<', $prod_price)放到->where('price','<', 500)它工作正常