【技术积累】树形结构的循环查找实现案例1
无限级服务端数据组织方案的实现,提供解决方案,其中数据库查询可替换为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;
}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。