hi! i'm trying to builid web catalog and i'm having problems with organizing
my tables. here's what i want:
i have main categories, sub_categories and articles like this:
CATEGORY_1
SUB_CAT_1
Article11
Article12
(...)
SUB_CAT_2
Article24
Article25
(...)
(...)
CATEGORY_2
SUB_CAT_3
Article35
(...)
(...)
(...)
and this is my idea how to do this:
1) first there's table CATEGORIES with "id" and "cat_name"
2) then there's table SUB_CATEGORIES with "id" and "subcat_nam e"
3) then table ARTICLES with "id", "subcat_id" , "article_na me" and
"art_price"
4) finally there's table with relations between categories and
sub_categories
like:
relations
id category subcategory
1 1 1
2 1 2
3 2 3
4 2 4
5 2 5
(...)
how i read results:
1) choose category : script outputs category name
2) sql query gets all sub_categories for selected category from table
"relations"
loop
3) output sub_category name
4) select all articles and prices for selected sub_category from
table "Articles"
5) output atricles and prices
till there's no sub_categories left
(sorry for long post)
my question is:
- is there any more elegant and faster way to do this?
thank you all!
my tables. here's what i want:
i have main categories, sub_categories and articles like this:
CATEGORY_1
SUB_CAT_1
Article11
Article12
(...)
SUB_CAT_2
Article24
Article25
(...)
(...)
CATEGORY_2
SUB_CAT_3
Article35
(...)
(...)
(...)
and this is my idea how to do this:
1) first there's table CATEGORIES with "id" and "cat_name"
2) then there's table SUB_CATEGORIES with "id" and "subcat_nam e"
3) then table ARTICLES with "id", "subcat_id" , "article_na me" and
"art_price"
4) finally there's table with relations between categories and
sub_categories
like:
relations
id category subcategory
1 1 1
2 1 2
3 2 3
4 2 4
5 2 5
(...)
how i read results:
1) choose category : script outputs category name
2) sql query gets all sub_categories for selected category from table
"relations"
loop
3) output sub_category name
4) select all articles and prices for selected sub_category from
table "Articles"
5) output atricles and prices
till there's no sub_categories left
(sorry for long post)
my question is:
- is there any more elegant and faster way to do this?
thank you all!
Comment