我需要在MLM中进行自动溢出注册

时间:2014-04-14 16:57:48

标签: php

我只需根据下面图像链接

中给出的系列找到自动注册的空位

http://i.imgur.com/qipmMBK.jpg

在这里,我编写了代码但无法正常工作

    <?php


require_once 'config.php';

$username = "kishore";

$log=mysql_query("select * from usertree where user='".$username."'");

$k=(mysql_fetch_array($log));

$left=$k['child_L'];
$right=$k['child_R'];

// function start

function child($child)
{
    $log1=mysql_query("select * from usertree where user='".$child."'");

    $k1=(mysql_fetch_array($log1));

    $left1=$k1['child_L'];
    $right2=$k1['child_R'];

    if ($left1 == NULL) {

        echo"register under child left on" . " " . $child ;

    }elseif ($right2 == NULL)  {

        echo"register under child right on" . " " . $child ;

    }else {

        child($right);
    }
}
// function end

if ($left == NULL) {

    echo"register under My child left on" . " " . $username ;

}elseif ($right == NULL)  {

    echo"register under My child right on" . " " . $username ;

}else {

    child($left);
}


?>

数据库视图链接

http://i.imgur.com/EGefeIF.jpg

如果我是用户,我的左,右,就像&#34; L&#34;和&#34; R&#34;

我想php应该自动chk可能的空位注册。像

1 = L,2 = R,3 = LL,4 = RL,5 = LR,6 = RR

       user
       / \
  (1) L   R (2)
     /\   /\
(3) LL LR RL RR (6)
      (5) (4) 

如果它找到&#34; RL&#34; position是空的(新用户应该注册&#34; RL&#34;)

0 个答案:

没有答案