[Need] Binary Tree by PHP & MySQL

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [Need] Binary Tree by PHP & MySQL

    Hi,

    I need a help regarding binary tree. My db table structure is: ID, userid, position, referid.

    Now I want to show this like binary tree:

    Code:
                          1
              ------------------
             |                    |
             2                    3
             |                        |
       ---------            -----------
      |          |          |              |
      4         5         6              7
    Can anyone help me to solve this?
    Last edited by asifnayem; 19.09.13, 12:13.

    #2
    Maybe some more info is required to answer this question as its not making much sense for what you need help with

    Comment


      #3
      Originally posted by something else View Post
      Maybe some more info is required to answer this question as its not making much sense for what you need help with
      Well, I'm creating a site where I need to have a binary tree for downline. Like if I refer someone to the site, he/she'll be my downline and will be putted under my tree (left/right).
      I've searched over the net but hardly find any solution. The hierarchy will looks like this image below:
      Click image for larger version

Name:	Untitled.png
Views:	1
Size:	3.8 KB
ID:	110744

      Comment


        #4
        i think binary tree concept makes no sense in php. it won't speed up array indexing.
        if you are worry about array performance then consider using PHP: SplFixedArray - Manual

        and binary tree is just a headache for example if sub tree `3` somehow break child tree (6, 7) will easily not accessible (but can be fixed with small math)

        for more info refer to Binary tree - Wikipedia, the free encyclopedia

        Comment


          #5
          Hi, @something else can you please help?

          Comment


            #6
            PHP Binary Tree Recursion Algorithm - Stack Overflow

            this one should help.
            sigpic

            Comment

            Working...
            X