Jump to content

mlm demo structure


drisate

Recommended Posts

Hey guys ;-)

I got a client that asked me today to create him an MLM type website. The first part of my work would be to test if there system works so I need to run a full demo of the multilevel structure.

 

The MLM structure works as follow: 1 person finds 2 members and they then find 2 more each and so on until we reach 100 level deep.

 

If i got this right,

At level 5 there will be 25 members

At level 10 there will be 100 members

At level 20 there will be 400 members

At level 40 there will be 1.600 members

At level 100 there will be 10.000 members

 

So at the end of the demo there should be 10k members inserted into the table

 

The table looks like this: id, parent, level, under

 

Parent is the ID of the guy that recruited him, level is the level that guy is at (level 1, 2 , 3, 4 or 5) and under is the number of people under him. I need to run a script that will insert all the data into that table so that we can run some test on the liability of the project so we can set the rates right.

 

At first I thought it would be a piece of cake ... but when I started I found out very fast that populating the MLM network 5 level deep is gona be tricky ... my first attempt gave me a result that looks like this:

      |0|
     |1|2|
   |x|x|3|4| 
x|x|x|x|x|x|5|6|

 

As you can see the script only grab the last id then adds 2 new members then uses the last one as the parent and starts over ... So my script is useless and I did not figer out how to do everything in 1 step ...

 

Any help would be appreciated.

 

Link to comment
Share on other sites

This is what i got so fare

 

$i = 1;

$INSERT = mysql_query("INSERT INTO mtable (id, parrain) VALUES ('', '0')");

while ($i <= 10) {
    if ($last!=""){$where = "WHERE $last";}
    $select = mysql_query("SELECT * FROM mtable $last") or die("<strong>SELECT * FROM mtable $last</strong><br>".mysql_error()); $i=1;
    while ($level = mysql_fetch_array($select)) {
        
        $INSERT = mysql_query("INSERT INTO mtable (id, parrain) VALUES ('', '$level[id]')");
        $INSERT = mysql_query("INSERT INTO mtable (id, parrain) VALUES ('', '$level[id]')");
        
        if ($last==""){$last .= " where id!='$level[id]' ";}else{$last .= " or id!='$level[id]' ";}
        if ($i=="10000"){echo "<h1>FIN</h1>";exit();}
        echo "$i | ";
        $i++;  
    }

}

 

As you can see the loop is not right.

 

$mtable = array(
  array('id'=>'1','parrain'=>'0'),
  array('id'=>'2','parrain'=>'1'),
  array('id'=>'3','parrain'=>'1'),
  array('id'=>'4','parrain'=>'2'),
  array('id'=>'5','parrain'=>'2'),
  array('id'=>'6','parrain'=>'3'),
  array('id'=>'7','parrain'=>'3'),
  array('id'=>'8','parrain'=>'1'),
  array('id'=>'9','parrain'=>'1'),
  array('id'=>'10','parrain'=>'2'),
  array('id'=>'11','parrain'=>'2'),
  array('id'=>'12','parrain'=>'3'),
  array('id'=>'13','parrain'=>'3'),
  array('id'=>'14','parrain'=>'4'),
  array('id'=>'15','parrain'=>'4'),
  array('id'=>'16','parrain'=>'5'),
  array('id'=>'17','parrain'=>'5'),
  array('id'=>'18','parrain'=>'6'),
  array('id'=>'19','parrain'=>'6'),
  array('id'=>'20','parrain'=>'7'),
  array('id'=>'21','parrain'=>'7'),
  array('id'=>'22','parrain'=>'1'),
  array('id'=>'23','parrain'=>'1'),
  array('id'=>'24','parrain'=>'2'),
  array('id'=>'25','parrain'=>'2'),
  array('id'=>'26','parrain'=>'3'),
  array('id'=>'27','parrain'=>'3'),
  array('id'=>'28','parrain'=>'4'),
  array('id'=>'29','parrain'=>'4'),
  array('id'=>'30','parrain'=>'5'),
  array('id'=>'31','parrain'=>'5'),
  array('id'=>'32','parrain'=>'6'),
  array('id'=>'33','parrain'=>'6'),
  array('id'=>'34','parrain'=>'7'),
  array('id'=>'35','parrain'=>'7'),
  array('id'=>'36','parrain'=>'8'),
  array('id'=>'37','parrain'=>'8'),
  array('id'=>'38','parrain'=>'9'),
  array('id'=>'39','parrain'=>'9'),
  array('id'=>'40','parrain'=>'10'),
  array('id'=>'41','parrain'=>'10'),
  array('id'=>'42','parrain'=>'11'),
  array('id'=>'43','parrain'=>'11'),
  array('id'=>'44','parrain'=>'12'),
  array('id'=>'45','parrain'=>'12'),
  array('id'=>'46','parrain'=>'13'),
  array('id'=>'47','parrain'=>'13'),
  array('id'=>'48','parrain'=>'14'),
  array('id'=>'49','parrain'=>'14'),
  array('id'=>'50','parrain'=>'15'),
  array('id'=>'51','parrain'=>'15'),
  array('id'=>'52','parrain'=>'16'),
  array('id'=>'53','parrain'=>'16'),
  array('id'=>'54','parrain'=>'17'),
  array('id'=>'55','parrain'=>'17'),
  array('id'=>'56','parrain'=>'18'),
  array('id'=>'57','parrain'=>'18'),
  array('id'=>'58','parrain'=>'19'),
  array('id'=>'59','parrain'=>'19'),
  array('id'=>'60','parrain'=>'20'),
  array('id'=>'61','parrain'=>'20'),
  array('id'=>'62','parrain'=>'21'),
  array('id'=>'63','parrain'=>'21')
);

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.