Am trying to make an referral system which has more than 10+ levels of hierarchy. The first level will have a 5 referrals. And next level will have 5*5 which would be 25 and by next level would be 25*5 = 125. So this is the way it goes on.
My concern is, how to track back and count number of referrals in each level from the last to the top parent id ?
Root User
-Level 1
- User1
- Level 1
- has 5 user
- Level 2 - has 25 users
- User2
- Level 1
- has 5 user
- Level 2 - has 25 users
- User3
- Level 1
- has 5 user, Level 2
- has 25 users
- User4
- Level 1
- has 5 user
- Level 2 - has 25 users
- User5
- Level 1
- has 5 user
- Level 2 - has 25 users
So according to the above example, when the user1, user2, user3, user4 and user5 reaches 5 people under each then the root users achieves 2 nd level which is 25 people and this tree goes on.
And what is the best approach to get the total count of users under root user ? whats the efficient way to find this. At this point i seriously dont have any idea how to approach this. So i dont have any code to show !Please guide