Php 使用特定属性选择
假设我们有3个表:产品、属性和详细信息 产品Php 使用特定属性选择,php,mysql,Php,Mysql,假设我们有3个表:产品、属性和详细信息 产品 id name price 1 pr1 120 2 pr2 140 3 pr3 200 4 pr4 165 id name 1 color 2 guarantee 3 resolution 4 year 5 contrast ratio id productId attributeId value 1 1 1 grey 2 1 2 yes 3
id name price
1 pr1 120
2 pr2 140
3 pr3 200
4 pr4 165
id name
1 color
2 guarantee
3 resolution
4 year
5 contrast ratio
id productId attributeId value
1 1 1 grey
2 1 2 yes
3 2 1 black
4 2 4 2011
5 2 5 70 000:1
6 4 2 no
属性
id name price
1 pr1 120
2 pr2 140
3 pr3 200
4 pr4 165
id name
1 color
2 guarantee
3 resolution
4 year
5 contrast ratio
id productId attributeId value
1 1 1 grey
2 1 2 yes
3 2 1 black
4 2 4 2011
5 2 5 70 000:1
6 4 2 no
详细信息
id name price
1 pr1 120
2 pr2 140
3 pr3 200
4 pr4 165
id name
1 color
2 guarantee
3 resolution
4 year
5 contrast ratio
id productId attributeId value
1 1 1 grey
2 1 2 yes
3 2 1 black
4 2 4 2011
5 2 5 70 000:1
6 4 2 no
例如,要选择颜色=黑色、年份=2011、对比度=70000:1的所有产品。在本例中,结果为id=2的产品。mysql的语法是什么
SELECT * FROM products, details WHERE products.id = details.productId
AND details.attributeId = 1 (For the first attribute)
AND details.attributeId = 4 (For the second and third attribute?)
...
使用
谢谢不知道如何使用“加入”。不客气。。。请不要忘记对任何有帮助的答案进行投票/标记为已接受。。。