簡體   English   中英

Webshop過濾器返回的行不正確

[英]Incorrect rows returned by webshop filter

我有一個名為product的表,其字段ID為NAME,URL,BRAND,然后有一個名為product_filter的字段,其ID為PRODUCT_ID,TYPE,VALUE

假設我有以下產品表

1 | 產品1 | 產品1 | 品牌1
2 | 產品2 | 產品2 | 品牌2
3 | 產品3 | 產品3 | 品牌1

和product_filter表

1 | 1 | 材料 羊毛
2 | 1 | 材料
3 | 2 | 材料
4 | 3 | 材料 羊毛
5 | 1 | 季節 秋季
5 | 2 | 季節 秋季
5 | 1 | 季節 所有

現在,當客戶在網頁上並嘗試進行過濾時

物料:羊毛,棉季節:秋季

我的結果是產品1(既有物料又有正確的季節)和產品2(有1物料又有正確的季節)。

我嘗試了加入

SELECT DISTINCT(shop_product.product_number), `shop_product`.`color_count`, `shop_product`.`category_id`, `shop_product`.`in_stock`, `shop_product`.`url_image`, `shop_product_description`.* FROM (`shop_product`) JOIN `shop_product_description` ON `shop_product`.`id` = `shop_product_description`.`product_id` JOIN `shop_category_description` ON `shop_product`.`category_id` = `shop_category_description`.`category_id` INNER JOIN `shop_filters` ON `shop_product`.`id` = `shop_filters`.`product_id` WHERE `shop_product`.`status` = 1 AND `shop_product_description`.`language_id` = '1' AND `shop_category_description`.`language_id` = '1' AND ( (shop_filters.type = '1' AND shop_filters.keyword = 'cotton') OR (shop_filters.type = '1' AND shop_filters.keyword = 'wool') ) AND (shop_filters.type = '2' AND shop_filters.keyword = 'fall') ORDER BY shop_product`.`url_image` asc, `shop_product_description`.`name` desc LIMIT 36    

我用Distinct取回了1個以上的產品(因為產品1具有兩種材料)。

但是直到改變我都沒有結果

( (shop_filters.type = '1' AND shop_filters.keyword = 'cotton') OR (shop_filters.type = '1' AND shop_filters.keyword = 'wool') ) AND (shop_filters.type = '2' AND shop_filters.keyword = 'fall')    

( (shop_filters.type = '1' AND shop_filters.keyword = 'cotton') OR (shop_filters.type = '1' AND shop_filters.keyword = 'wool') ) OR (shop_filters.type = '2' AND shop_filters.keyword = 'fall')    

但是,我的結果是棉或羊毛或跌落的產品。 如果有人提出建議,那么請...

您需要根據過濾器表多次匹配,以檢查每個過濾器。 最簡單的可能是進行多個聯接。

SELECT DISTINCT(shop_product.product_number), shop_product.color_count, shop_product.category_id, shop_product.in_stock, shop_product.url_image, shop_product_description.* 
FROM (shop_product) 
JOIN shop_product_description ON shop_product.id = shop_product_description.product_id 
JOIN shop_category_description ON shop_product.category_id = shop_category_description.category_id 
INNER JOIN shop_filters sf1 ON shop_product.id = sf1.product_id 
INNER JOIN shop_filters sf2 ON shop_product.id = sf2.product_id 
WHERE shop_product.status = 1 AND shop_product_description.language_id = '1' 
AND shop_category_description.language_id = '1' 
AND ( (sf1.type = '1' AND shop_filters.sf1 = 'cotton') OR (sf1.type = '1' AND sf1.keyword = 'wool') ) 
AND (sf2.type = '2' AND sf2.keyword = 'fall') 
ORDER BY shop_product.url_image asc, shop_product_description.name desc LIMIT 36

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM