如何使用php从mysql表中获取无限的父记录和子记录?

时间:2016-12-22 22:25:09

标签: php mysql

我写了这样的PHP代码。根据我的代码,我只能获得3个级别。如何获得无限的父母和孩子的水平。?

$GetNetworkList=mysql_query("SELECT * FROM txuser INNER JOIN txtusernet ON txuser.UserDid=txtusernet.UserDid WHERE txtusernet.Status=0 AND txuser.SponsNo='$DisCode'");
while($FetchNetworkList=mysql_fetch_array($GetNetworkList)){

echo "L1-" . $FetchNetworkList['DistribCode'] ."<br/>";

 $GetNetworkList1=mysql_query("SELECT * FROM txuser INNER JOIN txtusernet ON txuser.UserDid=txtusernet.UserDid WHERE txtusernet.Status=0 AND txuser.SponsNo='$FetchNetworkList[DistribCode]'");

    while($FetchNetworkList1=mysql_fetch_array($GetNetworkList1)){

        echo " L2-" . $FetchNetworkList1['DistribCode']."<br/>";

            $GetNetworkList2=mysql_query("SELECT * FROM txuser INNER JOIN txtusernet ON txuser.UserDid=txtusernet.UserDid WHERE txtusernet.Status=0 AND txuser.SponsNo='$FetchNetworkList1[DistribCode]'");

                while($FetchNetworkList2=mysql_fetch_array($GetNetworkList2)){   

                    echo "L3-" . $FetchNetworkList2['DistribCode']."<br/>";
                }
    }
}

输出

L1-9400013

L2-9400014

L3-9400015

L2-9400732

L3-9400733

L3-9401377

L1-9400012

L2-9400016

L3-9400155

L1-9400019

0 个答案:

没有答案