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 Jerry Stuckle on 09/01/06 12:28

hornedw wrote:
> Jerry Stuckle wrote:
>
>>hornedw wrote:
>>
>>>Jerry
>>>
>>>I was trying to set it up where when a person clicks on books the page
>>>would reload and then display Books and then Nonfiction and Fiction
>>>would appear under it. Like below
>>>Books (35)
>>>Electronics(23)
>>>
>>>The number inside the parenthesis being the number of products in that
>>>category. When Books is clicked on, it would display the following
>>>Books(35)
>>> Fiction(18)
>>> Nonfiction(17)
>>>Electronics(23)
>>>
>>>It does not necessaryly have to be spaced over. I may use bulleted list
>>>or something like that. The main two things I was trying to do was use
>>>the modfied preorder tree algorithm and to have it display the main
>>>category and then display the main category and its subcategories and
>>>then the rest of the categories on the page. I was debating on whether
>>>doing it this way or something similar to the way it is done at
>>>Amazon.com on their categories.
>>>
>>>David
>>>Jerry Stuckle wrote:
>>>
>>>
>>>>hornedw wrote:
>>>>
>>>>
>>>>>the category table should look like the following. it did not display
>>>>>very well in the first message
>>>>>
>>>>>catid, name,lft,rgt
>>>>>1, home,1,1
>>>>>2, books,2,17
>>>>>4, fiction,3,10
>>>>>5, nonfiction, 11,16
>>>>>3, electronics,18, 37
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>hornedw wrote:
>>>>>
>>>>>
>>>>>
>>>>>>I have been working on a ecommerce website for myself. What I needed
>>>>>>some assistance on was when i was trying to display the
>>>>>>categories/subcategories for the different products.
>>>>>>I decided to use the modified preorder tree transversal algorithm. What
>>>>>>I wanted was on the first page is to display the catogories as follows
>>>>>>
>>>>>>Books (35)
>>>>>>Electronics(23)
>>>>>>
>>>>>>The number inside the parenthesis being the number of products in that
>>>>>>category. When Books is clicked on, it would display the following
>>>>>>
>>>>>>Books(35)
>>>>>>Fiction(18)
>>>>>>Nonfiction(17)
>>>>>>Electronics(23)
>>>>>>
>>>>>>In my MYSQL database table, I have the fields catid, name, lft and
>>>>>>rgt. For example for the three categories mentioned above I have the
>>>>>>following entries
>>>>>>
>>>>>>catid name lft rgt
>>>>>>1 home 1 1
>>>>>>2 books 2 17
>>>>>>4 fiction 3 10
>>>>>>5 nonfiction 11 16
>>>>>>3 electronics 18 37
>>>>>>
>>>>>>
>>>>>>The first category home was just used to represent the main root of the
>>>>>>whole tree. If anyone could give me some assistance, it would be much
>>>>>>appreciated. Thank you in advance.
>>>>>
>>>>>
>>>>I guess I'm confused. How do you link from "fiction" or "nonfiction" to
>>>>books?
>>>>
>>>>This way of doing it looks quite confusing to me.
>>>>
>>>>
>>>>--
>>>>==================
>>>>Remove the "x" from my email address
>>>>Jerry Stuckle
>>>>JDS Computer Training Corp.
>>>>jstucklex@attglobal.net
>>>>==================
>>>
>>>
>>Yes, I'm aware of what you're trying to do. What I'm confused about is
>>how, from the information you provided, the system is supposed to know
>>that fiction and nonfiction fall under books. The example you have
>>doesn't show any way to determine if something is a top level category
>>or a subcategory - and if the latter, which is its parent category.
>>
>>P.S. Please don't top post.
>>
>>--
>>==================
>>Remove the "x" from my email address
>>Jerry Stuckle
>>JDS Computer Training Corp.
>>jstucklex@attglobal.net
>>==================
>
>
> I got most of my information from
> http://dev.mysql.com/tech-resources/articles/hierarchical-data.html
> Under the section where it says "Nested Set"
>
> I will try to explain using the example I gave.
>
> I noticed on my example that the rgt value for home should have been 38
> Here is the datbase values I had in my previous post
>
>
> catid, name,lft,rgt
>
>>>>>1, home,1,38
>>>>>2, books,2,17
>>>>>4, fiction,3,10
>>>>>5, nonfiction, 11,16
>>>>>3, electronics,18, 37
>
>
>
> Basically this algorithm sets up the data you are working in as a tree
> diagram.Each block has a left and right value. You start on the left of
> the root of the tree and go around the diagram and number the blocks. .
> If the item has a child, you will number the parent's left value and
> the child's left value. If the item is a child, you wll number the left
> value and then go to the right value of the child. The difference
> between the right and left value of a child is always 1. Once you have
> given the child its right value, you will go back up the tree and give
> the parent its right value Once you have reached the main parent under
> the root, you go to the next main parent that is under the root. You
> continue this until you have given the last main parent its right value
> and then you give the root its right value.
>
> In the example above, Home has the biggest difference between its right
> and left values and therefore is the root. Books is the first main
> parent category. The left and right values of fiction and nonfiction
> fall between the left and right values of books. That is how books is
> the parent category of fiction and nonfiction. Electronics is another
> main category in the table. The list I gave above is not a full list
> of al the categories and subcategories For example, I do not have any
> child subcategories listed. I know this not a very good explanation,
> but the website listed above may be of greater help of explaining what
> I am trying to do.
>
> David
>

David,

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

The only thing I'm not sure of is if MySQL will support recursive
queries - haven't tried it. If so, you can get your info in one sql
statement. Otherwise you'll have to do a little recursion in your PHP code.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

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

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