+ 3

How do I create a matrix tree?

How do I create a 2x2 matrix system where members who register falls under the matrix of their sponsor. Just like an MLM system. [edited] Here's what I really mean. I want to create a 2x2 matrix - a tree with 2 members on the first level and 4 members on the second level. At the top of the tree is member A. When new member registers with his referral link, a code will be run to check if his first level (2 nodes) is filled up with 2 members. If this is false, place the new member in level 1 else check if his second level(4 nodes) is filled up with 4 members. If this is false, place the new member in level 2 else search the database level by level for member A's referrals whose first level (2 nodes) aren't filled up yet and register the new member under such member (spillover). I know a loop will be used here and an increment operator but I don't really know how to go about it.

3rd Dec 2017, 6:21 AM
Victor Mbamara
Victor Mbamara - avatar
4 Answers
+ 1
Here's what I really mean. I want to create a 2x2 matrix - a tree with 2 members on the first level and 4 members on the second level. At the top of the tree is member A. When new member registers with his referral link, a code will be run to check if his first level (2 nodes) is filled up with 2 members. If this is false, place the new member in level 1 else check if his second level(4 nodes) is filled up with 4 members. If this is false, place the new member in level 2 else search the database level by level for member A's referrals whose first level (2 nodes) aren't filled up yet and register the new member under such member (spillover). I know a loop will be used here and an increment operator but I don't really know how to go about it.
3rd Dec 2017, 6:19 AM
Victor Mbamara
Victor Mbamara - avatar
+ 1
I get the idea here. I'll try to work it out with this. thanks
3rd Dec 2017, 2:15 PM
Victor Mbamara
Victor Mbamara - avatar
0
Can you explain your question more, I am not sure exactly what you are asking.
3rd Dec 2017, 4:17 AM
Adam Schmitt
Adam Schmitt - avatar
0
The easiest way to do this is using object oriented programming. I think PHP7 supports OOP. You can create a class called Member which will hold all of the attributes about each member. This also includes any sub members (first row in the 2x2 matrix tree). Those sub members are stored as two separate Member objects. Those member objects also have sub members (second row of the matrix tree). I would write the method so that when adding a new member, the function checks to see if there first member has 2 member objects. if not, the Mr is added as one of those 2 objects. If it does, the function passes the sun member objects ( one at a time) and the process is repeated until an empty slot is found. The syntax is wrong below, but it explains the general process. function addMember(Member newM) { if(this member has less than 2 members) { add new member to this members slots) } else { add new member to submember using recursion - call this method with submembers } }
3rd Dec 2017, 2:21 PM
Adam Schmitt
Adam Schmitt - avatar