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

Your name:

Reply:


Posted by Jamie Alessio on 03/15/05 02:44

> 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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация