Home » » Get total left or right child in mlm binary plan

Get total left or right child in mlm binary plan

Written By Unknown on Selasa, 26 Juli 2011 | 02.51

Hello friends. If you are planning to work on an mlm ( Multilevel Marketing ) website. And you need to find out total no of children in left or right leg.

This function will surely help you. It counts total left or right child of a member. You only need to pass the member_id and leg_position to this function. and it will return total no of children in your binary tree.

Please take care of your table structure. At a minimum it should be member_id(primary_key), parent_id and leg_position where leg_position contains the position of the child member i.e. left or right.

Note : You need to reset the $total variable to 0 before every function call otherwise it will return garbage value.
  function getTotalLeg($memid,$leg){
$sql="select member_id from members where
parent_id='".$memid."' and leg_position='".$leg."'";

$res=mysql_query($sql);

global $total;

$total=$total+mysql_num_rows($res);
$row=mysql_fetch_array($res);

if($row['member_id']!=''){
getTotalLeg ($row['member_id'],'l');
getTotalLeg ($row['member_id'],'r');
}

return $total;
}


Function Call

$total=0;
$left=getTotalLeg(''mlm10002","l");
$total=0;
$right=getTotalLeg("mlm10002","r");

In the above function call "l" denotes left leg and "r" denotes right leg position stored in the table.
Share this article :

Posting Komentar

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Kumpulan Kata Broadcast Blackberry - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger