gpt4 book ai didi

mysql - 在 Controller laravel 中查询 sql

转载 作者:行者123 更新时间:2023-11-29 07:37:58 25 4
gpt4 key购买 nike

错误:

SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有误;查看与您的 MariaDB 服务器版本对应的手册,了解在 '&& product_price > ?' 附近使用的正确语法在第 1 行(SQL:select * from table_products where && product_price > 0)

我的代码:

public function faq(Request $request) {

$pro = Product::all();
$p_1 = Product::where('product_price', '>', 0,'&&', 'product_price','<', 250)->get();
return view('fontend.errors.faq', compact('pro', 'p_1'));
}

最佳答案

您可以在查询中添加另一个 where() 以应用过滤器

$p_1  = Product::where('product_price', '>', 0)
->where('product_price','<', 250)
->get();

这将产生类似

的查询
select * from table_products where product_price > 0 and product_price < 250

或者你可以使用 ->whereBetween()

$p_1  = Product::whereBetween('product_price', [0, 250])
->get();

关于mysql - 在 Controller laravel 中查询 sql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47856306/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com