2021-12-05

If variable is certain condition then don't run part of sql statement at all

I have the following SQL statement:

"SELECT * 
FROM products 
WHERE productage >= '$age' 
  AND productbrand='$brand'
  AND productinterest='$interest'
  AND (productprice >= '50' OR productprice='none')
  AND productexpdate >= CURDATE();"

If however $age, $brand or $interest is "all" I would like them not to even be displayed, showing everything in the products table under that variable. Is this possible or would I need to make multiple SQL statements depending on what the $age, $brand or $interest value is?

I hope you understand my question, please let me know if not!



from Recent Questions - Stack Overflow https://ift.tt/3lzyave
https://ift.tt/eA8V8J

No comments:

Post a Comment