Page 1 of 1

Category/Sub-Category/Sub-Sub-Category

Posted: Fri Dec 15, 2006 10:25 am
by Hyaku
Hi!
I want to create an image gallery, that may include more then 4 sub-categories inside each other. For example:
Arhitecture->Maryland->Baltimore->Downtown->Old Houses
What would be a good way, how to save it in the database? do I need to have seperated table for each sub-category or should I use one table? any other suggestions? Thanks!

Posted: Fri Dec 15, 2006 11:42 am
by dibyendrah
You don't need separate table to do this. You can achieve this with the help of single table.

Make the table with the following attributes :

Code: Select all

cat_id
cat_name 
is_parent
is_parent if 0 then it is root. And if it is not 0 and contains a parent node id which will becomes a child of parent node with that value.

I guess that makes a concept of what you are trying to archive.

Posted: Fri Dec 15, 2006 11:57 am
by Hyaku
Thanks alot man!

Posted: Fri Dec 15, 2006 4:54 pm
by feyd
That appears to be a hierarchical structure.

There are two resources we have listed in our.. uh Useful Resources threads that talk directly of hierarchical structures. They may be a good read.