Am working on a project that needs to create children and grandchildren using a root ID
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
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.
[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]
The User_ID’s would not necessarily be in order but just an example
Then also, USER 1 would see the total of children and grandchildren he has
The maximum of Children = 5, grandchildren = 20 == (25)
I have created a table like this
id | name | password | totalfamily | grandparent | parent_id
---------------------------------------------------------------
I would want the table to be hold info like this the one below
id | name | password | totalfamily | grandparent | parent_id
1 jon ****** NULL NULL
2 mel ****** NULL 1
3 al ****** NULL 1
4 me ****** 1 3
if there is need for new table structure to make it work, that will be ok too.
I have done the procedures for registration(including checking for the parent_id and grandparent_id) and the logging in
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
I know it needs complex querying statements to execute
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.
Help anyone???
Thanks in advance.