This might be somewhat of an odd question, but I'm trying to create a filter for results, but the means of creating a query seems kind of odd to me.
Say I have 5 types of animals, by default it searches all types of animals, however then you can filter them.
So say we have Cats, Dogs, Reptiles, Birds, Fish. I want to filter out the fish and birds, how would I build a query to notice this? Do I really have to build a query for every single possible combination? That seems a little absurd.
example query for all:
SELECT * FROM animals WHERE type = "dogs" OR type = "cats" OR type = "reptiles" OR type = "fish" OR type = "birds"
Use the NOT IN
operator. For example, to filter out fish
and birds
:
SELECT * FROM animals WHERE type NOT IN ('fish', 'birds')
$array = array('fish', 'birds');
$filter = implode(",", $array);
"SELECT * FROM animals WHERE type NOT IN ($filter)"
This way you can dynamically fill your array and pass it to sql query.