Well, I have a situation, where I need to find all the Child, and Child of Child and so on, until no more records found.
for example, suppose,
There is a User A,
under A, there are a user B and C, under B, there is D,E and under C there is F,G and so on,
So what I want is that all the Child of A, Grand Child, Great Grand child etc etc until there is no more child. Well, another example could be the Family Tree, so in simple words I want all the descendants of A or any other user.
In the database, I have columns like this :
ID, ParentID, Name
So it will stats like this :
ID, ParentID, Name
1 0 A
2 1 B
3 1 C
4 2 D
.
.
.
.
.
Please guide me what should be the best approach to do this.
well, thanks for your addition, but I dont think that will help. That has no similarity. In that case, there is a defined depth (4) but in my case, the depth is not defined. It may be 1 or it may be 10 or even more.
Thanks for your reply, in fact, in my case its really infinite, its like an affiliate thing, and there are types of users.
For general user the commission will be given to Direct Referrals and 1 more lever. While for out special type users, the commission will be given based on the whole download no matter how deep is that. So I really do not know what the depth could be.
Well, I just wrote a PHP function to do this. In fact, it is not good in terms of performance, but I make it better, like I used some query optimization etc etc, for example, all the affiliate ids that has no child are RULED OFF at first step. and so on.
Thanks a Million people. I agree that generally, these things have certain depth.