1

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'));
}
4
  • what's your code on HomeController.php line 131? Commented Dec 17, 2017 at 15:48
  • thank you, bug in this old post I had fixed. Can you help me query mysql Commented Dec 21, 2017 at 13:56
  • Tag properly!!!!! It's either MySQL or SQL Server, can't be both. Commented Dec 21, 2017 at 17:35
  • ok i had fixed . Commented Dec 22, 2017 at 7:41

1 Answer 1

1

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.