I have a table like this:
product_id attribute_id
2 7,8
1 2,7
3 7
I also have a variable called $search_ids
which contains values to search for.
If $search_ids
has a value of 7
, I want it to return all 3 rows, but if it has a value of 2,7
or 7,8
I then want to return that row only.
I tried the following where $search_ids
has a value of 7, but this doesn't return the second row! And if I change the row's value from 2,7
to 7,2
then it returns that row also!
So right now the following query:
$q = "SELECT product_id FROM product_attributes
WHERE attribute_id IN ('$search_ids')
OR attribute_id IN ($search_ids)
returns
2
3
instead of
2
1
3