Hello:
I have a situation where I have several many-many table relationships and I am trying to figure out the best way to setup the relationships in the most efficient way.
As follows:
Table 1:
CREATE TABLE categories (
id int auto_increment not null,
name varchar(30) not null,
PRIMARY KEY (id)
);
Table 1 consists of main categories ex:
Mens
Womens
Childrens
Table 1 <-> Table 2: Many-Many
Table 2:
CREATE TABLE sub_1_categories (
id int auto_increment not null,
name varchar(30) not null,
PRIMARY KEY (id)
);
Table 2 consists of sub categories ex:
Shirts
Shoes
Pants
Table 2 <-> Table 3: Many-Many
Table 3:
CREATE TABLE sub_2_categories (
id int auto_increment not null,
name varchar(30) not null,
PRIMARY KEY (id)
);
Table 3 consists of sub sub categories ex:
Casual
Dress
Sport
Table 3 <-> Table 4: Many-Many
Table 4: Products Table
CREATE TABLE products (
id int auto_increment not null,
name varchar(30) not null,
PRIMARY KEY (id)
);
Table 4 consists of various products that can be in more than one sub category. ex:
Sport Shoe
Golf shirt
ect..
The part I am having a difficult time with is the linking tables to establish the relationships. What is the best way to go about this? I am dynamically pulling the categories from the database so someone chooses a main category (Mens, Womens or whatever). Then a sub category (Shirts, Pants or whatever). Then a sub sub category (Sport, Casual or whatever).
Sometimes there will not be any products at the current time in the selected category. What is the best way to create the linking relationship tables?
Thanks,
Troy
I have a situation where I have several many-many table relationships and I am trying to figure out the best way to setup the relationships in the most efficient way.
As follows:
Table 1:
CREATE TABLE categories (
id int auto_increment not null,
name varchar(30) not null,
PRIMARY KEY (id)
);
Table 1 consists of main categories ex:
Mens
Womens
Childrens
Table 1 <-> Table 2: Many-Many
Table 2:
CREATE TABLE sub_1_categories (
id int auto_increment not null,
name varchar(30) not null,
PRIMARY KEY (id)
);
Table 2 consists of sub categories ex:
Shirts
Shoes
Pants
Table 2 <-> Table 3: Many-Many
Table 3:
CREATE TABLE sub_2_categories (
id int auto_increment not null,
name varchar(30) not null,
PRIMARY KEY (id)
);
Table 3 consists of sub sub categories ex:
Casual
Dress
Sport
Table 3 <-> Table 4: Many-Many
Table 4: Products Table
CREATE TABLE products (
id int auto_increment not null,
name varchar(30) not null,
PRIMARY KEY (id)
);
Table 4 consists of various products that can be in more than one sub category. ex:
Sport Shoe
Golf shirt
ect..
The part I am having a difficult time with is the linking tables to establish the relationships. What is the best way to go about this? I am dynamically pulling the categories from the database so someone chooses a main category (Mens, Womens or whatever). Then a sub category (Shirts, Pants or whatever). Then a sub sub category (Sport, Casual or whatever).
Sometimes there will not be any products at the current time in the selected category. What is the best way to create the linking relationship tables?
Thanks,
Troy