i have database table with few text fields which i use to filter data , each of this text fields contain number data separated with colon ( for example ‘1:2:4:5:6:7:9’ )
id | title | field1 | filed2 | field3 |
1 | Some title1 |1:2:3:4:5:6:7 |1:2:3:6:7 | 1:2:4:5:7:9:10:11 |
2 | Some title2 |1:2:3:4:5:6:7:8:9:10:11 |1:2:3:4:5:6 | 1:2:4:5:7:9:10:11 |
3 | Some title3 |1:2:3:4:5:6:7 |1:2:3:6:9 | 1:2:4:5:7:9:10:11 |
4 | Some title4 |3:4:5:6:7:10:11 |1:2:3:10:11 | 1:2:4:5:7:9:10:11 |
5 | Some title5 |1:2:3:4:5:6:7 |1:2:3:6:7 | 1:2:4:5:7:8:9:11 |
6 | Some title6 |2:3:4:5:6:7:9 |1:2:3:6:7 | 1:2:4:5:7:9 |
using a search form i use check boxes for each parameters for field1, field2 and field3 and use php foreach to create LIKE ‘%parameter%’ for each field
my SQL query look like
SELECT * FROM table WHERE (field1 LIKE '%1%' OR field LIKE '%2%' ) AND (field2 LIKE '%1%' OR field2 LIKE '%2%')
unfortunately this query doesn’t give me good result since i get back rows which doesn’t match my idea 🙂
for example if checkboxes values 1,2,3,4,5,6,7 are selected by user
query need to return only 1, 3 and 5th row
is there any better solution for filtering this results
regards
Additional Info:
Let me try to explain you a little bit more the idea
User check chekboxes with some values (ie. 1,3,4,5,6,7) script need to return only results which contain those values in field1 same thing happens when user check other checkboxes which control field2 and field3 but for now it’s not important
Additional info pt2.
I’ll try to give you all better explanation what i want to achieve
I have search form with checkboxes and radio input fields, each checkbox group ( values from 1 to 10 ) are represent columns ( field1, field2, field3 ) in table, each value in columns field1 for example represent selected checkboxes ( which are set in admin panel for each row ) now by default all check boxes are selected and i get all results now when user deselect respective checkbox results need to be filtered up with rows according to filter
good example what i try to achieve is http://www.hotelscombined.com/City/London.htm
so if checkbox with value 2 is deselected it can’t be listed in results
BR
Sile
I think the problem is that
%1%matches not only1but also10,11, etc.It’s better to do something like this: