title: Binary Tree Using PHP & MySQL that creates 5 children and 25 grandchildren from registered members
body: <p>Am working on a project that needs to create children and grandchildren using a root ID</p>
  
  <p>It works in this way
  user_1 registers himself, he(user_1) also  registers 2, 3, 4, 5, 6 and have total(maximum) of 5 children
  user_2 registers 7, 8, 9, 10, 11
  user_3 registers 12, 13, 14, 15, 16
  and so on</p>
  
  <p>ON user_1's profile a tree table lists out his children and from his children,
  the grandchildren he has from each of the registered children is also displayed.</p>
  
  <pre><code>                                   1
   ----------------------------------------------------------------------
      |                  |                  |               |                |
       2                3                  4               5                6
  ---------------     ---------------   ---------------  ------------   -------------- 
  |   |   |  |  |     |   |   |  |  |   |  |   |  |  |   |  |  |  |  |  |  |  |   |   |
  7   8   9  10 11    12  13 14 15  16  17 18  19 20 21  22 23 24 25 26 27 28 29 30  31                        
  </code></pre>
  
  <p>The User_ID's would not necessarily be in order but just an example
  Then also, <strong>USER 1</strong> would see the total of children and grandchildren he has 
  The maximum of Children = 5, grandchildren = 20 == (25)</p>
  
  <p>I have created a table like this</p>
  
  <pre><code> id | name  | password | totalfamily | grandparent | parent_id
   ---------------------------------------------------------------
  </code></pre>
  
  <p>I would want the table to be hold info like this the one below</p>
  
  <pre><code>id | name  | password | totalfamily | grandparent | parent_id
  1     jon     ******                  NULL          NULL
  2     mel     ******                  NULL          1
  3     al      ******                  NULL          1
  4     me      ******                  1             3
  </code></pre>
  
  <p>if there is need for new table structure to make it work, that will be ok too.</p>
  
  <p>I have done the procedures for registration(including checking for the parent_id and grandparent_id) and the logging in</p>
  
  <p>But am in a fix concerning how to QUERY the database to help me list out the names like a tree structure to show the children and the grandchildren</p>
  
  <p>I know it needs complex querying statements to execute</p>
  
  <p>I am in urgent need of solving this(hope it doesn't break the rules) as I have spent days reading Hierarchical data structuring tutorials for my Mysql+PHP yet none seems easy to be heading my direction.</p>
  
  <p>Help anyone???
  Thanks in advance. </p>