Home > Mysql, database > How to create a directory structure ?

How to create a directory structure ?

How to create a directory structure ? or
How to creata a tree structure  ? or
How to design a database for a tree structure ? or
How to design a database for storing hierarchical structure ?

using single table

Create a table like this

database

CREATE TABLE `category` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(50) default NULL,
`descr` text,
`parent` int(11) default NOT NULL,
PRIMARY KEY  (`id`)
)

This table containing fields id,name,description and parent.Here all are familiar fields except parent.
Parent field is used to store the id of parent item . So that we can select the sub category by querying the database

with parent==id .

First upon we have to display main category by querying parent==’0′,
Then sub category by querying parent==1 or some thing like that
I think this information useful .

Regards,
Arun Raj R
Kadampanad

Categories: Mysql, database Tags: , , , ,
  1. No comments yet.
  1. No trackbacks yet.

Videos, Slideshows and Podcasts by Cincopa Wordpress Plugin