我有以下一组表,我希望根据用户点击FilterSub_ID
(属于all_filters
表)显示产品列表。
---------------------------------------------------------------------------
| dbo.Cat_Main | dbo.Cat_Sub | dbo.FiltersMain | dbo.FiltersSub |
|----------------- |------------------|------------------|------------------|
| Cat_Main_ID | Cat_Sub_ID | FilterMain_ID | FilterSub_ID |
| Cat_Main_name | Cat_Main_ID | FilterMain_Name | FilterMain_ID |
| other data..... | Cat_Sub_name | other data..... | FilterSub_Name |
| ............... | other data..... | ............... | other data..... |
| ............... | ............... | ............... | ............... |
--------------------------------------------------------
| dbo.all_cat | dbo.all_filters | dbo.Products |
|------------------|------------------|------------------|
| all_cat_ID | all_filters_ID | product_id |
| product_id | product_id | product_name |
| Cat_Main_ID | FilterMain_ID | other data..... |
| Cat_Sub_ID | FilterSub_ID | ............... |
| other data..... | other data..... | ............... |
换句话说,当用户点击特定FilterSub_ID
时,我需要将其移至另一个网页,在那里他将能够看到符合以下条件的产品列表:
SELECT *
FROM
all_cat, all_filters, Products, Cat_Main, Cat_Sub, FiltersMain, FiltersSub
WHERE
Products.product_id = all_filters.product_id
AND Products.product_id = all_cat.product_id
AND Cat_Main. Cat_Main_ID = all_cat. Cat_Main_ID
AND Cat_Sub. Cat_Sub_ID = all_cat. Cat_Sub_ID
AND all_cat.Cat_Main_ID = '" & Request.QueryString("c") & "' (exists in me URL)
AND all_cat. Cat_Sub_ID = '" & Request.QueryString("cy") & "' (exists in me URL)
AND This is the "FilterSub_ID" that continually takes new "FilterSub_ID" (when user clicks on it) and adds them to the previous (already exist) ones:
all_filters.FilterSub_ID = '" & Request.QueryString("FilterSub_ID") & "'
(通常,上面的一些表不必涉及查询,但我需要它们,因为它们包含不在必要表中的类别和过滤器的名称。这就是我将它们包括在内的原因。我的询问。)
到目前为止,我可以毫无问题地编写正确的查询。我真正需要的是,尽管我付出了很多努力,但我无法做到的是:
正如我之前提到的,当用户点击特定FilterSub_ID
时,在我要转移给他的新页面中,我也在包含所选FilterSub_ID
的网址中发送一个变量:FilterSub_ID=23
。
但我真正需要的是,每当用户选择其他FilterSub_ID
这个新的FilterSub_ID
添加到前一个FilterSub_ID=23& FilterSub_ID=24&FilterSub_ID=25&FilterSub_ID=26&...
时。所以,每次我都有这样的新网址:
FilterSub_ID=23& FilterSub_ID=24 FilterSub_ID=25 FilterSub_ID=26
如何根据不断添加到URL中的新ID同时连续更改我的sql查询,同时为同一个过滤器同时使用多个ID:
FilterSub_ID
我如何处理它们(所有这些)以便我的记录集能够同时根据所有这些MyValue
选择和显示正确的选定产品?
带有VBScript的SQL Server 2016 / Classic ASP
答案 0 :(得分:0)
我同意marc_s,我认为ANSI join是编写查询的更好方式,更简洁。
但你需要做的事实上很简单:
SELECT *
FROM
all_cat, all_filters, Products, Cat_Main, Cat_Sub, FiltersMain, FiltersSub
WHERE
Products.product_id = all_filters.product_id
AND Products.product_id = all_cat.product_id
AND Cat_Main. Cat_Main_ID = all_cat. Cat_Main_ID
AND Cat_Sub. Cat_Sub_ID = all_cat. Cat_Sub_ID
AND all_cat.Cat_Main_ID = '" & Request.QueryString("c") & "'
AND all_cat. Cat_Sub_ID = '" & Request.QueryString("cy") & "'
AND all_filters.FilterSub_ID IN (
/* use a loop here to concatenate the values that you got from the query string like so: */
24,
25,
26
)
在本质上,您可以以编程方式构建SQL,每次添加,过滤器的参数值,逗号(如果存在更多值)并循环显示,直到您没有更多值要添加。