I write a lot of information which might be not useful for you so if you want a simple question this is my question : (i want to know is there anyway to use OR
on SQL in other ways like this : WHERE age=18,19 AND gender='male','female'
OR something like this : WHERE age=[18,19] AND gender=['male','female']
) but if you didn’t understand what i want you can read more information in below.
Hi i have many foreach
function to make custom filter and i can’t finish it, in my sql code i have a search value at first which will search in all of columns and its work well.
I have 4 Select input which will help me to filter it i mean select boxes like age or gender or other things.
But the problem is , the select boxes are able to select multiple options as array and creating this kind of SQL is very hard.
I made 4 foreach
for my sql and its works until i just use one of my select boxes which means its not gonna work if i choose age and gender or something else because the sql will be something like that :
WHERE age=18 OR age=19 OR gender='male' OR gender='female'
AND the sql which im looking for is :
WHERE age=18 AND gender='male' OR age=18 AND gender='female' OR age=19 AND gender='male' OR age=19 AND gender='female'
But this is just an example and the code which i write will need very heavy SQL and its will be slow at first and i will die to fix it on foreach
functions so i want to know is there anyway to use OR
on SQL in other ways like this : WHERE age=18,19 AND gender='male','female'
OR something like this : WHERE age=[18,19] AND gender=['male','female']
Advertisement
Answer
It sounds like you want something like IN
… For example:
WHERE age IN (18,19) AND gender IN ('male','female')