我对产品和购物车下表:购物车 - 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和无限的属性(可以有更多的只有颜色和大小,但不是每个产品都有属性)。