无限级服务端数据组织方案的实现,提供解决方案,其中数据库查询可替换为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;
}
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。