Re: Question about how to handle something....

From: Date: Thu, 13 Sep 2001 04:25:31 +0000
Subject: Re: Question about how to handle something....
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-67130@lists.php.net to get a copy of this message
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 richard@zend.com address is an endangered species -- Use ceo@l-i-e.com 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 <jeff@hyrum.net> Newsgroups: php.general To: <php-general@lists.php.net> 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

« previous php.general (#67130) next »