Yup! That works just fine.
I took out all spaces after comma and it's ok now.
Thanks Jaime.
-afan
Jamie Alessio wrote:
I have table with products. In column categories are listed numbers
of categories a product belongs, like:
1. 21,
2. 35, 8, 72, 1, 4,
3. 23, 11, 48,
4. 65,
5. 11,
6. 23,
7. ...
(somebody else created the table this way and I have to keep it for
the moment)
Now, I have to list all products that belongs to category with cat.
number, e.g. 11.
Afan,
If you're using MySQL check out the FIND_IN_SET() function. Since your
category data is comma separated you should be able to do something like:
SELECT product
FROM products
WHERE
FIND_IN_SET('11', REPLACE (categories, ' ', '')) > 0
You need the extra REPLACE() call there to remove the spaces or else
FIND_IN_SET() for your numbers won't work properly.
Details on the function at
http://dev.mysql.com/doc/mysql/en/string-functions.html
- Jamie
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php