1
votes

Error:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '&& product_price > ?' at line 1 (SQL: select * from table_products where && product_price > 0)

my code:

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'));
}
1
what's your code on HomeController.php line 131?Ben
thank you, bug in this old post I had fixed. Can you help me query mysqlHonda hoda
Tag properly!!!!! It's either MySQL or SQL Server, can't be both.Eric
ok i had fixed .Honda hoda

1 Answers

1
votes

You could add another where() to your query to apply filter

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

this will produce a query like

select * from table_products where product_price > 0 and product_price < 250

or you could use ->whereBetween()

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