Forum Moderators: coopster
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
The lookup table should contain both a category id and a product id where each product id is mapped to N category ids.
This way you can use a simple JOIN and WHERE to pull information from either direction.
In any case try
...category REGEXP(\".*[^0-9]$category[^0-9].*\") ORDER by... or something roughly along these lines.
Otherwise, this might work. Regular expressions are the key to solving your problem. Isn't this a boundard word problem.
$sql = "SELECT * FROM table WHERE category REGEXP \"[[:<:]]$category%[[:>:]]\" ORDER by title DESC";
Just a thought, I'd have to test it.