I currently have a database that contains a bunch of different products. One of the columns (category) contains the category ID for each product. The catch is that some products are listed in multiple categories. To solve this problem the category column is varchar and contains data where the categories are delimited by a "|". For example, one record may have the following category "3|6|1|0".
I now want to pull up the records for only a specific category. Currently I've tried using wildcards but it isn't working perfectly. My SQL statement is currently the following:
$sql = "SELECT * FROM table WHERE category LIKE \"%$category%\" ORDER by title DESC";
This works for the most part except, when I pull up category 2 I also get results for category 20. Does mySQL have a way to split this field based on a delimiter and search each separated value?
Thank you in advance for your help.
Nick Ladd