You can use just the one table with a parent for each sub-category:
alter table category add parent int(11);
id parent name
1 NULL fruit
2 1 apple
3 1 banana
4 1 coconut
Now, suppose you need the sub-categories of the record with ID #1
(IE, all the fruits)
select id, name from cateogory where parent = 1
You could even generate *ALL* the relationships with a "SELF-JOIN"
This is where you kinda "fake out" SQL to think of the table from two
view-points at once:
Your query would be:
select super.id, super.name, sub.id, sub,name
from category as super, category as sub
where sub.parent = super.id
order by super.name, sub.name
--
WARNING [EMAIL PROTECTED] address is an endangered species -- Use
[EMAIL PROTECTED]
Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm
Volunteer a little time: http://chatmusic.com/volunteer.htm
----- Original Message -----
From: Jeff Lewis <[EMAIL PROTECTED]>
Newsgroups: php.general
To: <[EMAIL PROTECTED]>
Sent: Wednesday, September 12, 2001 9:07 AM
Subject: Question about how to handle something....
We have categories set up and I was using PHP to make searches on this. It
was working nicely and the categories were auto incremented as new ones were
added.
Now we're adding sub categories and the categories are all labelled the same
way....
When I load one page I use PHP to generate a drop down box of the categories
and this is easy but now I need to do sub categries as well... Anyone have
a way to do this in mind? Like how can I do both.
Should I create a new table to hold these sub categories and enter them in
but somehow link them to the main categories? So when building thedrop down
boxes it wouldbe like:
Computers - Programming (value of this would be something like 1/8) I would
then split the two values to do searches?
Jeff
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]