I'm trying to create a SQL Query that gets data from my DB depending on what the array includes.
Example:
My array includes 1, 2, 3 then the query should be SELECT * FROM v WHERE category='1' OR category='2' OR category='3'.
Does anyone know a way to achieve this?
Any tips are welcome.
UPDATE:
Using MySQL as DB.
You can use implode function and IN clause as
$sql="SELECT * FROM v WHERE category IN ('".implode("','", $your_array)."')";
I would take a look at https://stackoverflow.com/a/14767572/755949, which uses placeholders and PDO to add the parameters to your query. Going with Saty's answer you could risk ending up with a SQL injection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With