Jump to content

can i ask for help please?


Vinmark

Recommended Posts

uhm i am currently working on a Multilevel Marketing System. i'm using php.

it is a genealogy that is 2x2 matrix.

every member can have 2 downlines.

my problem is how can i count all his total downlines per side.

 

example chart.

                      SIDE A                                        SIDE B

 

                                                member1

                      member2                                      member3

        member4            member5            member6            member7

member8      NULL  NULL        NULL  NULL      NULL  NULL      NULL

 

 

total Downline at Side A : 4

total Downline at Side B : 3

 

this is my table

memberid | parentid | child_a | child_b

 

sorry for my bad english. :(

 

can you give me any idea on how to this? and code this then post it here for help again? pls?

 

 

Link to comment
Share on other sites

I am not 100% positive what you are asking for, but it appears that your data is effectively a binary tree.  You said that each member can have two downlines which is incredibly similar to a statement such as "each node can have a maximum of two children."  If that is the case then the code to do this is really quite simple -- in fact, any search through a binary tree should work.  You might want to look up an in-order search (or pre-order or post-order if you prefer).  I think you simply need to get the root of the tree and then initialize 2 counters:

 

- one counter for the number of non-null nodes starting with root.left  (aka root->left)

- a second counter for the number of non-null nodes starting with root.right (aka root->right)

 

 

I haven't done much data-structure/OOP coding in PHP but in Java, a simple recursive algorithm that does a return like:

 

if (this != null)
{
  return 1 + findMembers(this.left) + findMembers(this.right);
}
else
{
  return 0;
}

 

should do the trick.  That's about all I can offer you.

Link to comment
Share on other sites

  • 2 weeks later...

passing them to array, you will waste memory

imagine if there are like 180000 members (which is market america got currently after 18 years)

and at least like 90k members

so, u will have 90k array? each array hold a member's name, or id, the bottom is less memory

but the top few, they got a huge array

wat a waste

 

if you jsut use 2 array with 90k members per array

you will need to find out which member belongs which side (any member beyong 2nd level) this is more complicated

 

 

i think this is the system looks like market america (they already got the system working very well)

what i can come up is

have a class, and some recursive function

this is like of like a tree

 

let's assume this in c++, cause i know more in c++

you have this struct

struct node{

int total;

node *previous;  //points his upline

node *left; //points to his left downline

node *right; //points to his right downline

}

 

void counting(node n){

while(n->left=NULL){

n->previous->total++; //give the upline 1 downline counting

countTotal(n);

counting(n->left);

}

while(n->right !=NULL){

n->previous->total++; //give the upline another downline counting

countTotal(n);

counting(n->right);

}

}

 

void countTotal(n){

while(n->previous!=NULL){

n->previous->previous->total=n->previous->previous->total+n->previous->total;  //sum up the upline's upline's total

countTotal(n->previous);

}

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.