我有3个表:dbo.Category,dbo.SubCategory和dbo.Product,结构如下:
dbo.Category: (Category_ID, Category_name)
dbo.SubCategory: (SubCategory_ID, Category_ID, SubCategory_name)
dbo.Product: (Product_ID, Category_ID, SubCategory_ID, Product_name)
例如,我需要这样的东西:
第1类
---子类别1(7)
---子类别2(11)
第2类
---子类别5(88)
---子类别9(36)
第3类
---子类别8(0)
---子类别22(122)
我不熟悉经典的asp和vbscript,直到现在我唯一能做的事情,只是我的主要类别的第一个循环如下:
<%
dim Connect,RS_test,sql
Set Connect = Server.Createobject("ADODB.Connection")
Connect.Open = MM_sindesi_STRING
sql = "SELECT * FROM dbo.Category"
set RS_test = Connect.Execute(sql)
%>
<%
Do Until RS_test.Eof
%>
<table width="100%" border="1" cellspacing="1" cellpadding="1">
<tr>
<td><%=RS_test("Category_name")%></td>
</tr>
</table>
<%
RS_test.MoveNext
Loop
%>
<%
Connect.Close()
Set RS_test = Nothing
Set Connect = Nothing
%>
上面的代码工作正常,但我唯一得到的是我的类别名称......
我已经尽力在stackoverflow中找到一些类似的问题,但不幸的是我没有找到任何东西......
答案 0 :(得分:0)
您使用嵌套的Do Loop
<%
set category = server.createobject("adodb.recordset")
SQL="SELECT * FROM dbo.Category"
category.open SQL,Connect,1,3
%>
<%i=0%>
<% Do while not category.eof %>
<%i=i+1%>
<%=i> Category Record
<table width="100%" border="1" cellspacing="1" cellpadding="1">
<tr>
<td><%=category("Category_name")%></td>
</tr>
<%
cat_id=category(Category_ID)
set sub_category = server.createobject("adodb.recordset")
SQL="SELECT * FROM dbo.SubCategory where Category_Id="&cat_id&""
sub_category.open SQL,Connect,1,3%>
<%j=0%>
<% Do while not sub_category.eof %>
<%j=j+1%>
<%=j%> Record Sub Category
<tr>
<td><%=category("SubCategory_name")%></td>
</tr>
<%
sub_category.MoveNext
Loop
%>
</table>
<%
category.MoveNext
Loop
%>