PHP递归 - 增加查询变量

时间:2014-04-30 20:13:52

标签: php mysql recursion

我有一个数据库,其中每一行都包含一个唯一的用户ID号码,以及一个引用号码,用于将它们链接到引用它们到站点的人员。我正在尝试创建一个递归函数,只要它继续查找用户,就会搜索数据库,并执行多次计算。以下是我到目前为止的情况 - 我一直在尝试创建递增的查询变量 - 请帮助!

function findrepsloop($refidnum, $num){

    echo "FINDREPSLOOP STARTED<br><br>";

    if(strlen($refidnum) > 0){

        echo "FIRST STRLEN IF LOOP PASSED: $refidnum<br><br>";                  
        $totalreps++;   

        $query{$num} = "SELECT * FROM user WHERE (refidnum = '$refidnum' && active = 'YES') ";
        $result{$num} = mysql_query($query{$num});
        $line{$num} = mysql_fetch_array($result{$num}, MYSQL_NUM);                  
        $total{$num} = mysql_num_rows($result{$num});

        echo "QUERY $num found $total{$num} rows in the database. LINE 0: '$line{$num}[0]<br><br>";

        $totaltemp = 0;
        if($total{$num} > 2){ $totaltemp = $total{$num} / 3; $totaltemp = floor($totaltemp); }else{}                    
        $numberofthrees = $numberofthrees + $totaltemp;                     

        while(strlen($line{$num}[0]) > 0){

            $refidnum = $line{$num}[0];
            $num++;
            findrepsloop($refidnum, $num);

            $line{$num} = mysql_fetch_array($result{$num}, MYSQL_NUM);
        }

    }else{

    }   

}

0 个答案:

没有答案