Re: Category and sub-category logic

From: Date: Fri, 15 Aug 2003 16:30:09 +0000
Subject: Re: Category and sub-category logic
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-159717@lists.php.net to get a copy of this message
--- "CPT John W. Holmes" <holmes072000@charter.net> wrote: > From: "Mark" <mark_weinstock@yahoo.com> > > > > I'm trying to get a handle on this algorithm as well. If you add > > additional children to a parent record, doesn't that require > > renumbering all the rgt and lft values in the lineage? For > example > > (table shamelessly stolen from a website): > > > > Personnel > > emp lft rgt > > ====================== > > 'Albert' 1 12 > > 'Bert' 2 3 > > 'Chuck' 4 11 > > 'Donna' 5 6 > > 'Eddie' 7 8 > > 'Fred' 9 10 > > > > If I want to add 'Joe' as a subordinate to 'Fred', doesn't that > mean > > I have to change the lft values for Fred, Chuck, and Albert? Yes, > > deleting definitely seems easier. I'm curious about adding... > > Yes, you will have to update all of the right and left numbers to > the right > (or higher) than the node where you are inserting. Deleting is > basically the > same method done in reverse, but can get complicated when you > delete a node > and have to determine what to do with the children. > > I'd recommend, if you're really interested in this, to do some > searching on > nested set tutorials. You could specifically search for Joe Celko > who has > written a lot of information on the topic. Thanks. I'll take a look. I'm considering changing to this algorithm from my basic parent-ID table. > > While it seems like a big deal to have to update all of the > numbers, it's > really not. It can be done with a single query (with subselects). > Yes, it's > more costly than inserting a name into an adjacentcy list model, > but it's > worth it for all that you gain from the nested set model. > > ---John Holmes... > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > ===== Mark Weinstock mark_weinstock@yahoo.com *************************************** You can't demand something as a "right" unless you are willing to fight to death to defend everyone else's right to the same thing. *************************************** __________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com

« previous php.general (#159717) next »