Well, if you have everything setup right.. this is easy to do in SQL.
Lets say you have your root table:
create table root(
id integer unsigned not null auto_increment,
description varchar(50),
key root_key (id)
);
and your sub categories:
create table subcats(
id integer unsigned not null auto_increment,
root_id integer unsigned not null,
description varchar(50),
key subcat_key (id)
);
and your final category:
create table subsections(
id integer unsigned not null auto_incremnt,
parent_id integer unsigned not null,
description varchar(50),
key subsec_key (id)
);
now you can simply join all these tables..
SELECT subsection.description,subcats.description,root.description
FROM subsection,subcats,root
WHERE (
(subcats.root_id=root.id) AND
(subsections.parent_id=subcats.id) AND
(root.id=N)
);
(where N is the root.id number you are looking for)
that way, in root you could have 'Sports' In subcats you would have 'Sports
Equipment', 'Sports Stories', etc..
in subsection, you could have 'Golf Clubs' etc.. and so on
or you could divide it up more and go from Sports Equipment, to Golf to Golf
Equipment..
hope this helps..
---------------------
Johnny Withers
[EMAIL PROTECTED]
p. 601.853.0211
c. 601.954.9133
-----Original Message-----
From: Isaac Force [mailto:[EMAIL PROTECTED]]
Sent: Sunday, March 04, 2001 5:03 PM
To: [EMAIL PROTECTED]
Subject: Recursive queries
Quick searches of Google and the MySQL page didn't turn up anything, so I'll ask here..
Here's what I have:
I have a table that among others, have fields called 'section_id' and 'parent_id'. The
section_id is the id of the "self" section,
and the parent_id is the id of the section that "owns" the self section. (It's sort of
like a filesystem where one directory has
subdirectories, and so on)
Here's what I'm trying to do:
I want to start with one section, and go down the tree of sub-sections, picking up
information about them on the way.
Example:
I want to start at the "root" section, and follow down one of it's sub-sections.
(Root)
|
|--- Sports Products
| |
| |--- Golf :: Item1, Item2, Item3, Item4
| |
| |--- Fishing :: Item5, Item6, Item7, Item8
So it will start at Root, find that Sports Products is attached to Root, get the
information I want from Sports Products, then it
will find that Golf and Fishing are attached to Sports Products, and get the
information from them respectively. (And so on) As it
stands, it won't go any further than 2 levels deep from the root section, so I won't
need to find a more effecient way to organize
the relationships for now.
What do you all feel would be the best way to do this?
--
Isaac Force [EMAIL PROTECTED]
(503)656-2489 http://gorgonous.dhs.org
Real Users find the one combination of bizarre
input values that shuts down the system for days.
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php