溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

【技術積累】樹形結構的循環(huán)查找實現(xiàn)案例1

發(fā)布時間:2020-08-03 17:59:09 來源:網(wǎng)絡 閱讀:303 作者:yc26583 欄目:web開發(fā)

無限級服務端數(shù)據(jù)組織方案的實現(xiàn),提供解決方案,其中數(shù)據(jù)庫查詢可替換為List的方式查找等其它方式。

function queryAllSubCustomers($cstId) {
$sqlA="SELECT ID, Name, ParentID FROM T_CustomerInfo WHERE ID = $cstId ";
$custList=Sql_Query($sqlA);
$AllCustInfs=array();

$result=array();
while(count($custList) > 0) {
    // 組建當前客戶列表,獲取所有id
    $countNum = count($custList);
    $subCustIds=" (";
    //print_r($custList);
    for ($i=0; $i<$countNum; $i++) {
        $custInf = $custList[$i];
        $node=array();
        $node['id']=$custInf['ID'];
        $node['text']=$custInf['Name'];
        array_push($AllCustInfs,$node);
        $subCustIds = $subCustIds.$custInf['ID']."," ;
    }

    $subCustIds = substr($subCustIds,0,-1).") ";
    // 查詢下級客戶
    $sql="SELECT ID, Name, ParentID FROM T_CustomerInfo WHERE ParentID <> 0 AND ParentID IN $subCustIds ";
    unset($subCustIds);
    unset($custList);
    $custList=Sql_Query($sql);
    //print_r($custList);
}
return $AllCustInfs;

}

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內容。

AI