我對產品和購物車下表:購物車 - multple屬性值
//產品表
Products:
id | Product_value
-----------------------
1 | Product 1
Attributes:
id | Attribute_value
-----------------
1 | Color
2 | Size
Attribute_values:
id | Attribute_id | Value_value
---------------------------------
1 | 1 | Black
2 | 1 | Red
3 | 1 | Blue
4 | 2 | S
5 | 2 | M
6 | 2 | L
7 | 2 | XL
Product_attribute_values
Product_id | Attribute_id | Value_id
--------------------------------------
1 | 1 | 1
1 | 1 | 2
1 | 1 | 3
1 | 2 | 4
1 | 2 | 5
1 | 2 | 6
1 | 2 | 7
//數據庫表
Cart:
id | product_id | number_value
----------------------------------
1 | 1 | 1
2 | 1 | 1
Product_attribute_value:
Cart_id | attribute_id | value_id
--------------------------------------
1 | 1 | 1
1 | 2 | 4
2 | 1 | 2
2 | 2 | 5
所以:
- 客戶希望產品1在黑色si澤小號
- 客戶希望產品1在紅色大小爲M
一種產品可以包含多個屬性的值。
通過在車與AJAX-> JSON將產品我有以下數據:
- productid
- number
- attribute= array( // example: color
attribute_id
value_id
)
- attribute= array( // example: size
attribute_id
value_id
)
隨着其查詢(PDO)1可以看到,如果該組合已經存在?如果存在,我想更改此產品的編號
在'How to find all the products with specific multi attribute values'處,它們使用EXISTS。 我如何做到這一點與PDO和無限的屬性(可以有更多的只有顏色和大小,但不是每個產品都有屬性)。