I'm developing a MLM website and the order in which people signup (and under who) matters for commissions. Users have a Right-Leg and a Left-Leg of their genealogical tree they can place new signups into. If you have people in your Left-Leg, you are able to see everyone in THEIR left leg as well. If you have people in your Right-Leg, you can see everyone in THEIR Right-Leg as well. However, it doesn't stop here. There is no limitation as to how far down the tree can go; even people who are 50+ members removed from you (someone who signed up under you got a signup and they got a signup and that signup got a signup, etc...).
The way I've organized the system is that everyone is given a member number, a leg number, and a sponsor number. The member number is an auto-incrementing field, the leg number is either a 0 for left or a 1 for right leg, and the sponsor number is the member number of the person above you. I also have a signup_date field to track signups (however member numbers work fine for this since they always grow larger).
I'm running into two issues.
1) Coding this to print using 'while' statement seems to work until you realize that it has to eventually change from member to member and after the first level, the sponsor number changes and I loose the 'while' statement. I also need to be careful because not all members who have a higher member number than you are under you, so each level has to be specificly tied to the previous sponsor number.
2) Coding this to show up as a sequentially growing tree is an issue. Even if I get the code working correctly, it needs to 'look' like a tree system and I'm not doing a good job. I was trying to figure out how to use an 'if' statement to force members of members to show up offset to either side (left or right respectively) whenever the 'while' statement hit them while members directly below show up directly under their respective sponsor.
I'm a bit over my head. Any suggestions?
Start Free Trial