Jump to content

mlm double loop


drisate

Recommended Posts

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

[...]

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

<?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?

Link to comment
Share on other sites

<?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

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.