I have a form where users can search all the entries in a table and i’m having problems with a specific entry.
I’ll give an example for a better understanding:
The user can check 5 boxes: 1, 2, 3, 4, 5 and he checks all the boxes.
If the specific row has the value ‘1|2|3’, my search query won’t find it.
Beforehand i get the post variable in php (which is an array) and add ‘%’ before and after every value. In this case: ‘%1%2%3%4%5%’
My search query:
SELECT id FROM table WHERE string LIKE '%1%2%3%4%5%'
In this case, it won’t find the row with the value ‘1|2|3’.
I guess it’s normal this way and it works great the other way around but I want to perform a query that matches parts of the original string. In my case ‘%1%2%3%4%5%’ to match ‘1|2|3’.
How can i do this?
Thanks in advance for taking the time.
EDIT: Can i do this without multiple AND, OR operators?
just change it to this:
this would solve your problem – but you should really think about normalizing your database (in this case, store 5 different flags as 1/0 for the five different settings instead of putting them all together in one field).