Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Plz! MLM System.. HELP REQUIRED!!

Codes here !

Moderators: macek, egami, gesf

Plz! MLM System.. HELP REQUIRED!!

Postby bahrian » Tue Feb 04, 2003 12:58 am

Hello there...
i want to get some help on databases and programming...
i know php :idea: at intermediate level.. and MySQL too...and ofcourse MS ACCESS too
now what i want is .. to develop an MLM system... i hope you people know what it is..
anyway ..i am clearing it..
it starts from one member... and then that person refers two people... and then every new comer refers more two.. in this way .. a BINARY TREE starts growing... by binary it means that... every entity has two childs.... hope you are getting it....
its like

O
/ \
O O
/ \ / \
O OO O

i can store every member's record in a databae and ofcourse can retreive that too..
the problem is that.. i have to show every member's LEFT and RIGHT DOWNLINE... meaning.. referral of referral is also under that person's dowline... i have to count and then show that this person has this much people in left downline and this much in right downline..Can anyone help please?????

and i need URGENT HELP!! if anyone can....
i need the loop structure and the logic for this.. as it involves database too..
bahrian
New php-forum User
New php-forum User
 
Posts: 3
Joined: Wed Dec 04, 2002 10:39 pm
Location: Islamabad

Postby Joan Garnet » 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

Postby Joan Garnet » 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

Thanks! but let me check and understand it

Postby bahrian » Tue Feb 04, 2003 9:40 pm

Thanks "Joan Garnet"!
right now i can not understand it, as i've just seen it... but i am trying to ... i am checking and understanding it..
but at the same time... tell me what about this 170?
do we have to know the total number of recrods or something???
as i want every member in downline or at any position to view his own downline.. not just the total downline... i hope you get my point now...
now i am checking this one.. and you see if you can help me any further..
once again THANKS! :)
bahrian
New php-forum User
New php-forum User
 
Posts: 3
Joined: Wed Dec 04, 2002 10:39 pm
Location: Islamabad

Postby Joan Garnet » 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!
User avatar
Joan Garnet
Moderator
Moderator
 
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars


Return to mySQL & php coding

Who is online

Users browsing this forum: rtlm1234 and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.