我需要显示一些产品列表。我有 2 张桌子,一张带有categories
,一张带有所有products
.
我需要显示这个结构:
list 1.
write - categories_id from categories table
write - list of products with the above categories_id from products table
end of list
next list2.
write - next categories_id from categories table
write - list of products with the above list2 categories_id from products table
end of list
等等...
因此,我需要从类别中选择所有类别 ID,并从产品表中选择所有匹配的类别 ID。
这样做的最佳方法是什么?我应该从里面选择所有categories
,然后在做直到...选择所有产品...还是?
假设类别表中有 4 个类别,因此它应该显示 4 个列表,每个列表中有 10 个产品。我拥有的 sql 如下所示:
sql3 = "SELECT * from categories c inner join products p on c.categories_id = p.categories_id where p.userid ='1' group by c.categories_id order by c.categories_id;"
and the do until looks like:
do until rs.eof
rs("categoriName")
rs("productsName")
rs.movenext
loop
但这会生成 4 个列表,每个列表中只有 1 个产品?
好的,我的表格如下所示:
categories table:
categories_id, userId, categoriesName
products table:
products_id, user_id, categories_id, productsName
And the do:
<% do until rs.eof %>
Categori: <%=rs("categoriesName")%>
Product:<%=rs("productsName")%>
<% rs.movenext
loop %>
列表应如下所示:
(list 1)
Categori: Phones
Product: iPhone
Product: Samsung
Product: Nokia
(list 2)
Categori: Tvs
Product: Philips
Product: Sony
Product: Sharp
也许我只是想在一个选择中执行此操作是错误的,也许我只需要两个选择,第一个选择类别名称并循环通过该循环,然后在该循环内选择产品。?