一直以来,我以及我周围的朋友对阿里巴巴产品分类情有独钟,具体截图如下:

除了长期使用下来的操作习惯,这样做产品分类的确有很独特的优点:1.树形结构,一目了然;2.附上产品数量,直接看出哪些是热点,无需再去通过其他途径寻找..
面对这样的分类方式,对我来说是一个不大不小的挑战,为什么呢?挑战一:网站系统从开始到现在一直为单级目录,没有接触过多产品多目录的网站;2.除了程序,这需要一个合适的数据库结构;3.参数循环有点绕头;4.貌似还涉及一点点数组的概念..
还好搞定了..废话不多说了,直接贴上源代码(ASP版),代码写的不简介,这里只记录完成了这一功能,具体的效率优化后续再做努力!
<div class="winstyle2">
<%set rs2=server.createobject("adodb.recordset")
sql2="select * from productdb"
rs2.open sql2,conn,1,1%>
<h2><img src="<%=weburl%>images/motuo/customGroupTitle.gif" border="0"> Products [<%=rs2.recordcount%>]</h2>
<%rs2.close
set rs2=nothing%>
<ul>
<%set rs=server.createobject("adodb.recordset")
sql="select top 20 typeid,typename from productype where sortid=0 order by typeid asc"
rs.open sql,conn,1,1
if rs.eof and rs.bof then
Response.Write"<br>No productsort!"
end if
do while not rs.eof
sqlid=""
set rs2=server.CreateObject("adodb.recordset")
sql2="select typeid,sortid from productype where sortid="&rs("typeid")
rs2.open sql2,conn,1,1
if rs2.eof and rs2.bof then
sqlid=rs("typeid")
else
do while not rs2.eof
sqlid=rs2("typeid")&","&sqlid
rs2.movenext
loop
end if
rs2.close
set rs2=nothing%>
<li class="oncate" >
<img src='<%=weburl%>images/motuo/open.png' alt='<%=rs("typename")%>' border='0'/> <a href='<%=weburl%><%=StrReplace(rs("typename"))%>.html' title='Chinese <%=rs("typename")%>' target="_self"> <%=rs("typename")%></a>
<%set rs3=server.CreateObject("adodb.recordset")
sql3="select * from productdb where typeid in("&sqlid&")"
rs3.open sql3,conn,1,1%>
[<%=rs3.recordcount%>]</li>
<%rs3.close
set rs3=nothing
set rs1=server.CreateObject("adodb.recordset")
sql1="select top 20 typeid,typename,sortid from productype where sortid="&rs("typeid")
rs1.open sql1,conn,1,1
if rs1.eof and rs1.bof then
else
do while not rs1.eof
set rs4=server.createobject("adodb.recordset")
sql4="select * from productdb where typeid="&rs1("typeid")
rs4.open sql4,conn,1,1%>
<li class="parcate" ><img src='<%=weburl%>images/motuo/icon_arrow.gif' alt='<%=rs("typename")%>' border='0'/> <a href='<%=weburl%><%=StrReplace(rs1("typename"))%>.html' title='Chinese <%=rs1("title")%>' target="_self"> <%=rs1("typename")%></a> [<%=rs4.recordcount%>]</li>
<%rs4.close
set rs4=nothing
rs1.movenext
loop
end if
rs1.close
set rs1=nothing
rs.movenext
loop
rs.close
set rs=nothing%>
</ul>
</div>