You are here: Re: displaying categories/subcategories using modified preorder tree transversal « PHP Programming Language « IT news, forums, messages
Re: displaying categories/subcategories using modified preorder tree transversal

Posted by mootmail-googlegroups on 09/01/06 14:56

Jerry Stuckle wrote:
> All I can say is - that has got to be one of the WORST implementations
> I've ever seen. Talk about making a simple problem complex - this takes
> the cake.
>
> I wouldn't even try implementing something like this.
>
> Rather, keep it simple:
>
> id parent description
> 1 null books
> 2 1 nonfiction
> 3 1 fiction
> 4 null electronics
>

At first glance, something like a preorder-tree traversal setup is
needlessly complex. I agree that the example you provided is much
easier to visualize conceptually.

I agree because I have made that mistake in the past. We had a project
that involved massive trees (we're talking the bill of materials for an
entire automobile down to an individual screw), and went with the
simple 'parent' scheme, but were too deep into the project before we
suddenly regretted it. A scheme like that is easy to set up, but a
nightmare to use and maintain.

To get a node and its children from the example you gave (known as the
Adjacency model), you have to rely either on recursion or knowing
exactly how many levels exist. The former introduces significant
overhead while the latter is just bad hard-coding. Using a more
advanced tree algorithm allows for a much easier time working with
nodes and children. The link provided earlier
(http://dev.mysql.com/tech-resources/articles/hierarchical-data.html)
is a great resource for seeing the different queries required to work
with either scheme.

I doubt the OP will be dealing with trees quite as large as the ones I
needed to use, but if you can deal with a bit of complexity up front,
you can save yourself a lot of extra work later on.

And speaking of the original post...I didn't quite understand what you
were asking. If you were asking for advice on getting the # of items
in each category, perhaps you could use the examples on that page
linked to for getting all the children of a node, and then WHERE'ing it
to include only those nodes whose lft & rgt are 1 apart (meaning they
have no children).

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация