I'm working on a form processed by PHP where multiple categories are saved to a MySQL table. Currently I have one table column for each category. For example I have a column in my table for "is_category1", and a column for "is_category2", and one for "is_category3", etc. (Those aren't the real column names, that's just for simplicity).
The problem is that we keep adding new categories, and I'd rather not add a new column every time we do. So I was thinking I could store the categories as a single string in a column called "categories" and have a character for each category. For example if the string is "100" it would mean is_category1=true, is_category2=false and is_category3=false.
That all works very well.
The problem is that I don't see a good way to perform searches. For example if I want to find every item where is_category2==true, I don't know of a SQL query to do that without iterating through each item in the table and processing the "categories" string. And there are over 50,000 items in the table, so that would be unacceptably slow.
Does anyone happen to have any advice about how to handle this? Maybe there's a SQL search method that can process the Xth item of a string?
Or a better way to store the "categories" item than a string?
Or am I just doomed to have a table column for every category?
Thanks for any help.