Page 1 of 1

generate hierarchical tree view

Posted: Tue Aug 11, 2009 11:15 am
by dheeraj
hello guys, i m trying to generate hierarchical tree view, as per done in any MLM business, where binary level or unary level tree has made....

in my problem there is a super user, below him there are many sub users this level will be called 1st level.
after tht the user's of first level will contain another child user, tht will be 2nd level, after 2nd there is 3rd level, then 4th & so on.... upto 8th level....

so i want to show this in tree view, it could be horizontal or vertical.... bt i m nt getting hw to do it... so plz help me...

Thanks.

Re: generate hierarchical tree view

Posted: Tue Aug 11, 2009 12:49 pm
by requinix
So the first level can have any number of users but after that only one per parent? Odd.

You can take the same approach to this as you would if it were a normal (any number of children per parent) tree.

This is the easiest form of HTML tree to build:
  • Root
    • A
      • 1
        • i
    • B
      • 2
    • C
      • 3
        • iii
    • D
What does your database look like?

Re: generate hierarchical tree view

Posted: Tue Aug 11, 2009 1:29 pm
by aceconcepts

Re: generate hierarchical tree view

Posted: Tue Aug 11, 2009 9:31 pm
by dheeraj
Thanx tasairis to reply....

i want the same thing u hd drawan there....
& i m taking a numeric user_ids for all the user, & a username & both will be unique...

Re: generate hierarchical tree view

Posted: Tue Aug 11, 2009 10:10 pm
by requinix
The HTML for such a structure looks like

Code: Select all

<ul>
    <li>Item<ul>
        <li>Sub item<ul>
            <li>Sub sub item</li></ul></li>
        <li>Next sub item</li></ul></li>
    <li>Next item<ul>
        <li>Sub next item</li></ul></li>
</ul>
<ul> starts a list, <li></li> marks an item, and </ul> ends the list.

Now,

Code: Select all

function makeListForUser($user) {
    echo "<ul>";
    /* foreach list of sub users for $user as $subuser */ {
        echo "<li>"; /* echo $subuser; */
        makeListForUser(/* $subuser */);
        echo "</li>";
    }
    echo "</ul>";
}
makeListForUser(/* root user */);
Try to fill in the comments there.