Hi guys, I'm new in php and i'm having a problem. My problem is, how to print and save to database. here is the schema,

1
   / \
  2   3
 /\   /\
4 5  6  7

what is php algorthym for that case?. 1 is sponsor for 2 and 3, 2 is sponsor for 4 and 5, 3 is sponsor for 6 and 7.

would you like to give me some glimpse or the logic, i want to store that tree into the database also. so when i input how many node you want, (eq 7 nodes) the structure will be like that. any one can help?

thanks a bunch.

Hans

I have worked on a few of these in the past and there are several things that you have to consider when setting this up. Like how many people can be sponsored by one individual, what do you do if the sponsor leaves, etc. Usually what I do is set up a separate table to track the 2 sponsors above a member.
Record_ID int 11
Member_ID int 11
Sponsor_ID int 11
SSponsor_ID int 11

Then when I need the data I join to the member table for actual names and other info.

I have worked on a few of these in the past and there are several things that you have to consider when setting this up. Like how many people can be sponsored by one individual, what do you do if the sponsor leaves, etc. Usually what I do is set up a separate table to track the 2 sponsors above a member.
Record_ID int 11
Member_ID int 11
Sponsor_ID int 11
SSponsor_ID int 11

Then when I need the data I join to the member table for actual names and other info.

Hi Rodney,

thank you for your kind reply, I've already figure it out how make that happen. here is code :

$jml=5 // number ids	
			$ids=1 // sponsor's id
			$f=0; // flag
			
			echo '| i | ids | pos | <br />';	
			
			for($i=1;$i<=$jml;$i++) //loop
			{	
			  $pos=1;			
			  $x=$now_id+$i;
			  if($f%2==1){ $ids++;  $pos=2; }	
							
			   echo  $i.' - ' .$ids. ' - ' .$pos. '<br />';		
			   $sqltree="INSERT INTO tree (id,idmember,idsponsor,pos,stat,level) VALUES('$x','$idmember','$ids','$pos',0,'basic')";
		   	   $dotree=mysql_query($sqltree) or die (mysql_error());
				
			   $f++; //increment si f
					
		}

the code works very well to, after i experimenting that issue, finally i came up with that codes. And now the problem how to print it into the TREE Hirarcy based on sponsorID, any idea?

thanks.

I would need to see the actual table layouts for that one and need to find out what you need in the output.

$jml=5 // number ids    
        $ids=1 // sponsor's id
        $f=0; // flag

        echo '| i | ids | pos | <br />'; 

        for($i=1;$i<=$jml;$i++) //loop
        {   
          $pos=1;           
          $x=$now_id+$i;
          if($f%2==1){ $ids++;  $pos=2; }   

           echo  $i.' - ' .$ids. ' - ' .$pos. '<br />';      
           $sqltree="INSERT INTO tree (id,idmember,idsponsor,pos,stat,level) VALUES('$x','$idmember','$ids','$pos',0,'basic')";
           $dotree=mysql_query($sqltree) or die (mysql_error());

           $f++; //increment si f

    }