drisate Posted February 13, 2012 Share Posted February 13, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/256984-mlm-demo-structure/ Share on other sites More sharing options...
drisate Posted February 13, 2012 Author Share Posted February 13, 2012 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') ); Quote Link to comment https://forums.phpfreaks.com/topic/256984-mlm-demo-structure/#findComment-1317593 Share on other sites More sharing options...
drisate Posted February 14, 2012 Author Share Posted February 14, 2012 bump ---> Nobody? Quote Link to comment https://forums.phpfreaks.com/topic/256984-mlm-demo-structure/#findComment-1317984 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.