私はいくつかの製品のリストを表示する必要があります。 私はcategories
と1つで、products
の2つのテーブルを持っています。テーブル1のカテゴリとテーブル2の製品を選択しますか?
そして私は、この構造を表示する必要があります。
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
のように...
だから私は、カテゴリと製品テーブルからすべてのマッチングcategories_idsからすべてのcategories_idを選択する必要があります。
これを行う最善の方法は何ですか? categories
からすべてを選択してから、do ...まですべての製品を選択するか...または?
カテゴリテーブルには4つのカテゴリがあるので、各リストには10の商品で4つのリストが表示されます。私が持っている 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
しかし、これはそれぞれにわずか1製品で4つのリストを生成しますか?
[OK]を、私のテーブルは次のようになります。
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
たぶんイムは、ちょうど1つの選択でこれをやろうと間違って考えて、多分私だけ2つの選択肢が必要です。最初はカテゴリ名を選択し、それをループしてループ内で商品を選択します。ここで
これは基本的なSQLです。あなたが扱うことができないすべてのSQLクエリについて質問をすることによって完全なプログラムを作ることができないので、本を読んで読むのが良いです。 – Aristos