利用递归获得无限分类的父类名称getParentCategoryFullName

来源:互联网 发布:iphone和mac互传文件 编辑:程序博客网 时间:2024/05/29 09:04

tableName:
    ProductCategory

CategoryID   自动编号
ParentCategoryID  数字
CategoryName    文本

CategoryIDParentCategoryIDCategoryName
10特色产品
20软件产品
30产品代理
41清防垢系列类
51油气井增产类
61钻井应用类
71特殊行业应用类

 

<%
function getParentCategoryFullName(CategoryID,conn,FullName)
 if CategoryID=0 then
  getParentCategoryFullName="无父类"
  exit function
 end if
 Set rs1=Server.CreateObject("ADODB.Recordset")
 strSQL="SELECT CategoryName,ParentCategoryID FROM ProductCategory WHERE CategoryID=" & CategoryID
 rs1.Open strSQL,conn,1,1
 tmpID=rs1.fields(1).value
 tmpName=rs1.fields(0).value
 rs1.close
 set rs1=nothing
  if FullName<>"" then
   FullName= tmpName & "-" & FullName
  else
   FullName=tmpName
  end if
 if tmpID<>0 then
  FullName=getParentCategoryFullName(tmpID,conn,FullName)
 end if
 
 getParentCategoryFullName=FullName
end function
%>