drisate Posted February 19, 2012 Share Posted February 19, 2012 Hey guys i need to generate a table for a multilevel marketing simulation of 10.000 members. It's a bi-level. All i need is a table with id, parrent I am lost with the double loop ... Quote Link to comment Share on other sites More sharing options...
MMDE Posted February 19, 2012 Share Posted February 19, 2012 Is this meant for someone specific, or is there just something I don't get... I see no code or anything to help you with?? Quote Link to comment Share on other sites More sharing options...
drisate Posted February 19, 2012 Author Share Posted February 19, 2012 I did not post my code because it's really off the track ... // INSERT $parrain = 0; $i = 1; $INSERT = mysql_query("INSERT INTO abibtech (id, parrain) VALUES ('', '0')"); while ($i <= 100) { if ($last!=""){$where = "WHERE $last";} $select = mysql_query("SELECT * FROM abibtech $last") or die("<strong>SELECT * FROM abibtech $last</strong><br>".mysql_error()); $i=1; while ($level = mysql_fetch_array($select)) { $INSERT = mysql_query("INSERT INTO abibtech (id, parrain) VALUES ('', '$level[id]')"); $INSERT = mysql_query("INSERT INTO abibtech (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++; } } id parrent 1 0 2 1 3 1 4 2 5 2 6 3 7 3 8 1 9 1 10 2 11 2 12 3 13 3 14 4 15 4 16 5 17 5 18 6 19 6 20 7 21 7 22 1 23 1 [...] i dont get how to loop level by level 100 times (Would be equal to 10.000 members) 0 11 2222 33333333 4444444444444444 [...] Quote Link to comment Share on other sites More sharing options...
trq Posted February 19, 2012 Share Posted February 19, 2012 Your post is very unclear. What exactly is the issue? Quote Link to comment Share on other sites More sharing options...
drisate Posted February 19, 2012 Author Share Posted February 19, 2012 I need to populate a table of 10.000 members. They each need to be connected by folowing the bi-level marketing laws .. 1 member finds 2 members, Ex: 0 12 3456 [...] My problem is i dont have a clue of how to generate such a table. Everything i tryed did not work. Knowing that 10.000 members = 100 level deep in the pyramide, i started with a while loop of 100, but how the hell can i loop only the last level. In the above exemple, the last level is 3456. The last level should be the members that does not yet have 2 recruted members. Quote Link to comment Share on other sites More sharing options...
MMDE Posted February 19, 2012 Share Posted February 19, 2012 <?php $members = 10000; // you can edit this one $person = 0; for($i=1; $person<$members; $i*=2){ for($j=0; $j<$i && $person<$members; $j++){ $person++; echo ($person-1); } echo '<br />'; } ?> echo pow(2,$rows); Quote Link to comment Share on other sites More sharing options...
drisate Posted February 19, 2012 Author Share Posted February 19, 2012 Thx MMDE. i got that same result once but unfortunatly it's not good. this is what it outputed 1, 1 2, 1 3, 2 4, 1 5, 2 6, 3 7, 1 8, 2 9, 3 10, 4 11, 1 12, 2 13, 3 14, 4 15, 5 16, 1 17, 2 18, 3 19, 4 20, 5 It should output 1, 0 2, 1 3, 1 4, 2 5, 2 6, 3 7, 3 8, 4 9, 4 10, 5 11, 5 12, 6 13, 6 14, 7 15, 7 16, 8 17, 8 18, 9 19, 9 20, 10 Quote Link to comment Share on other sites More sharing options...
MMDE Posted February 19, 2012 Share Posted February 19, 2012 <?php $members = 10000; // you can edit this one $j=1; $person=0; for($i=0; $person<$members; $i++){ while($j<2 && $person<$members){ $person++; $j++; echo $person . ', ' . $i . '<br />'; } $j=0; } ?> This outputs exactly what you just posted, but I'm not entirely sure this is what you really want? Is it a tree you want to create, where every branch splits into two new ones? Quote Link to comment Share on other sites More sharing options...
drisate Posted February 19, 2012 Author Share Posted February 19, 2012 OMG you did it !!! it works !!! Thank you !!! Quote Link to comment Share on other sites More sharing options...
litebearer Posted February 19, 2012 Share Posted February 19, 2012 <?PHP $i = 0; $query = "INSERT into table (parent) VALUE('$i')"; /* $result = mysql_query($query); */ echo "member id = " . ($i + 1) . " - query is " . $query . "<br />"; $i=1; $member_id = 2; while($i<10000) { $query = "INSERT into table (parent) VALUE('$i')"; echo "member id = " . $member_id . " - query is " . $query . "<br />"; /* $result = mysql_query($query); */ $member_id ++; $query = "INSERT into table (parent) VALUE('$i')"; /* $result = mysql_query($query); */ echo "member id = " . $member_id . " - query is " . $query . "<br />"; $member_id ++; $i = $i + 1; } ?> edit too late - slow fingers LOL Quote Link to comment 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.