Re: can't pull products from DB with REGEXP?

From: Date: Tue, 15 Mar 2005 00:44:21 +0000
Subject: Re: can't pull products from DB with REGEXP?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-210726@lists.php.net to get a copy of this message
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

« previous php.general (#210726) next »