You are here: Re: [PHP] can't pull products from DB with REGEXP? « PHP « IT news, forums, messages
Re: [PHP] can't pull products from DB with REGEXP?

Posted by Marek Kilimajer on 03/15/05 02:20

afan@afan.net 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.
>
> If I use query:
> select * from products where categories like '11, '
> product no. 5 will be listed but not product no. 3
>
> select * from products where categories like '%11,% '
> will list products 3 and 5 but
> select * from products where categories like '%1,% '
> will list products 2, 3 and 5 too - and, 3 & 5 are wrong.
>
> I got from friend this solution:
> select * from products where categories REGEXP '(^".$cat_num."|,
> ".$cat_num.")'

As each record has trailing comma, include that too:
(^2,|, 2,)

Would it be that difficult to convert the column to SET Type?
http://dev.mysql.com/doc/mysql/en/set.html

> it works just fine if I use 2 digit cat number. e.g. 11 or 26 or 62. But
> if I select for cat. num. 2 it will list all products from categories 2
> and everything between 20 and 29. 32 or 62 will not be listed.
>
> Confusing, ha?
>
> Thanks for any help!
>
> -afan
>

 

Navigation:

[Reply to this 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

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