我觉得这个问题可能已经被问过了一千次,所以如果有人回答,我会道歉.如果是这样,有人能指出我正确的帖子/链接?
我要做的是为我的网站构建一个分面导航.它使用MySQL,这里是我正在使用的表的草图:
products: - id - title - description
attributes: - product_id - name - value
categories: - id - name
products_to_categories: - product_id - category_id
我想要做的是当你在一个类别时显示可用属性列表,允许你为每个属性选择一个或多个值.举个例子,请查看Office Depot的这个页面:http://www.officedepot.com/a/browse/binders/N=5+2177/
到目前为止,我已经使用了很多连接来过滤多个属性:
SELECT products.*, a_options.* FROM products_to_categories AS pc, products, attributes AS a_options, /* list of attribute/value pairs I can continue to refine on */ attributes AS a_select1 /* first selected attribute */ attributes AS a_select2 /* second selected attribute */ ... WHERE pc.category_id = 1 AND products.id = pc.product_id …