Page 1 of 1

Need help to categorise the data

Posted: Mon Sep 06, 2010 1:25 pm
by max196
Hello Friends, :)

I created a MySQL database containing data as,

product_id with data - 1200, 1201, 1202.....
product_name with data - product1, product2, product3......
all_category_id(varchar75) with data - (3, 2), (1, 15, 2), (3, 7, 9) ....(two or more category id as varchar. since, many products have more than one category)

Every category ID has a name e.g
1 - arts
2 - entertainment
3 - Games
15 - movies

I'm trying to pull the product list category wise e.g.
select * from tablename where category=1(that is arts)

I used "regexp" but not working perfectly, e.g.
when i say,
select * from tablename where field regexp '.1.';

it returns, products from arts and also movies category as it contains "1" in its ID "15" But I want the list of only arts

So can anyone suggest me solution to get the desired result? I don't want to change the database structure

Thankx in Advance :)

Re: Need help to categorise the data

Posted: Tue Sep 07, 2010 5:17 am
by lorenzo-s
Obviously the pattern .1. matches also 15 or 51 :)
I don't know MySQL regex pattern syntax, but try something like [^0-9]1[^0-9], that means one charater that is not a number, number 1, one charater that is not a number. :D