I have a data stored as comma separated in the database field. Like say in a field colors
there are following rows.
red,blue, green
blue, white, purple, pink
yellow, khaki, maroon, orange
gray, lemon, black, brown
Next user has a textbox in a html form, where he enters a colors in a comma separated form. I want to search the database to return records matching his input. For example.
If I enter red, purple, orange
, then the query should return three rows because first row has red, second row has purple and third has orange.
I m not getting the way to easier than breaking the user inputs into array and looping through each colors and search the database to get results. Is there any easier way to do this?
Edit
I know storing data in comma separated form is not a good practice but I m working on a updates on application which was made by other programmer. And at this stage I cannot afford to change table structures.
Thanks