Plz! MLM System.. HELP REQUIRED!!

Codes here !

Moderators: egami, macek, gesf

Post Reply
User avatar
Joan Garnet
Moderator
Moderator
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars
Contact:

Tue Feb 04, 2003 11:58 am

Well,
I've got a script for you.
I'm not good with maths... but... I did it :)

Code: Select all

<?php 
$total_people = 107;
$total_lines = sqrt($total_people);//square root of total people
$position=0;
for ($i=0;$i<$total_lines+1;$i++){ //lets build the lines
   if ($position < $total_people){//if there's still people that need a position...
      $this_line = pow(2, $i);//the power of the current line (will be the total people o it)
      echo "ROW - ".$i." --> <p>";
      for ($j=0;$j < $this_line;$j++){
         if ($position < $total_people){//if there's still people that need a position...
            $position++;
            $my_array[$i][]=$position;//feed the array
            echo $position." - ";
            
         }else{
            break;//get out of the array because no more people need a postition
         }
      }
      echo "<br>";
   }else{
      break;//get out of the array because no more people need a postition
   }
}
echo "<pre>";//the shape of the array
print_r($my_array);
echo "</pre>";
?>



execute this code and use it as you need.
As you see there is an array ordered by rows and numbers. Each number can be the "id" for a name in a database, so you can access positions and do whatever you want with them.

I hope it helped!
;)

User avatar
Joan Garnet
Moderator
Moderator
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars
Contact:

Tue Feb 04, 2003 4:16 pm

Here you are the three search methods:

Code: Select all

<?php
echo "<h2>THE TOTAL PEOPLE IN THE PYRAMID</h2>";
$total_people = 107;
$total_lines = sqrt($total_people);//square root of total people
$position=0;
for ($i=0;$i<$total_lines+1;$i++){ //lets build the lines
   if ($position < $total_people){//if there's still people that need a position...
      $this_line = pow(2, $i);//the power of the current line (will be the total people o it)
      echo "ROW - ".$i." --> <p>";
      for ($j=0;$j < $this_line;$j++){
         if ($position < $total_people){//if there's still people that need a position...
            $position++;
            $my_array[$i][]=$position;//feed the array
            echo $position." - ";
            
         }else{
            break;//get out of the array because no more people need a postition
         }
      }
      echo "<br>";
   }else{
      break;//get out of the array because no more people need a postition
   }
}
echo "<pre>";//the shape of the array
print_r($my_array);
echo "</pre><p>*****************************************************************************************************</p>";
/////////////////////////////////////////////////////////////////
//Let's check how many people the nº53 member has on his right://
/////////////////////////////////////////////////////////////////
echo "<h2>the total people on the right in the same line of the chosen member</h2>";
$member = 53;
$total_lines = sqrt($member);//square root of total people
$position=0;
for ($i=0;$i<$total_lines+1;$i++){ //lets build the lines
   if ($position < $member){//if there's still people that need a position...
      $this_line = pow(2, $i);//the power of the current line (will be the total people o it)
      echo "ROW - ".$i." --> <p>";
      $count=0;
      for ($j=0;$j < $this_line;$j++){
         if ($position < $member){//if there's still people that need a position...
            $position++;
            $my_array[$i][]=$position;//feed the array
            echo $position." - ";
            $count++;
         }else{
            echo "<hr>There are <b>".($count-1)."</b> people on the right in the same line of member <b>".$member."</b><hr>";//the total people on his right (before him in the same line)
            break;//get out of the array because no more people need a postition
         }
      }
      echo "<br>";
   }else{
      break;//get out of the array because no more people need a postition
   }
}
echo "<pre>";//the shape of the array
print_r($my_array);
echo "</pre><p>*****************************************************************************************************</p>";
/////////////////////////////////////////////////////////////////
//Let's check how many people the nº37 member has on his left:///
/////////////////////////////////////////////////////////////////
echo "<h2>the total people on the left in the same line of the chosen member</h2>";
$member = 37;
$total_people = 153;
$total_lines = sqrt($total_people);//square root of total people
$position=0;
for ($i=0;$i<$total_lines+1;$i++){ //lets build the lines
   if ($position < $member){//if there's still people that need a position...
      $this_line = pow(2, $i);//the power of the current line (will be the total people o it)
      echo "ROW - ".$i." --> <p>";
      $count=0;
      for ($j=0;$j < $this_line;$j++){
         if ($position < $member){//if there's still people that need a position...
            $position++;
            $my_array[$i][]=$position;//feed the array
            echo $position." - ";
            $count++;
         }else{
            if($count < pow(2, $this_line)){
               $left_people++;
               echo "<b>".($position+$left_people)."</b> - ";
            }
         }
      }
      echo "<br>";
   }else{
      echo "<hr> There are <b>".$left_people."</b> members on the left of member nº <b>".$member."</b><hr>";
      break;//get out of the array because no more people need a postition
   }
}
echo "<pre>";//the shape of the array
print_r($my_array);
echo "</pre><p>*****************************************************************************************************</p>";
?>

I'm sure you can do it with array functions, but I did it with for itinerations...

User avatar
Joan Garnet
Moderator
Moderator
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars
Contact:

Wed Feb 05, 2003 9:15 am

You only need to know the total people in the case where we build the total structure (part one)
and when we need to know how many people there is on the left of the member (after him) (part three)

The case in the middle (part two) just counts until the chosen member. There's no need to know anything else.

The numbers 107, 53....etc.. are hipotetic. I invented it to run the sample..
You have to replace them with the POST or GET vars of the form that will create the query to the database.

bye!

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 2 guests