PDA

View Full Version : Categories and Sub-Categories


Steph
Sat 1st Jun '02, 7:08am
Hi! Im attempting on creating a database of review articles. THe part Im having difficulty with is category and subcategory support.

This is what I was thinking but I have no idea if Im on the right track or not.

Best place to start is MySQL database....

id | cat_name | parent_id
1 | cat1 | 0
2 | cat2 | 1
3 | cat3 | 2
4 | cat4 | 1


I used "0" to designate that as a main category.

OK. Am I at least going in the right direction???

~Steph

Dan615
Sat 1st Jun '02, 7:44pm
You have seperate tables for categories and then things inside the categories:


# The category table...

create table cats (
cid int primary key auto_increment not null,
cat_name varchar(255) not null
);

# And the things that go in the categories...I'm just gonna call it "thingies"

create table thingies (
tid int primary key auto_increment not null,
cid int not null, # a reference to the category
thingy_name varchar(255) not null
);


That's also how many forums are set up *cough* ;)