【发布时间】:2013-09-06 09:01:40
【问题描述】:
您好,我需要一些帮助。 我有 3 张桌子
**Products**
product_id //eg 1
product_name //eg apple imac
description // mplah mplah
category_id // 3 - desktops
...
**Features**
feature_id // 1
feature_name // processor
category_id // takes the parent-category eg computers with id = 1
and a pivot table **product_features** that should have something like this
product_id // 1
feature_id // 1
feature_value // intel i5
每个表还代表一个模型(所以我有一个 product_model、feature_model 和一个 product_feature_model - 我还不确定它是否需要 -)
在我看来,我有一个用于插入/编辑的表单,我想在其中获取特定类别的所有功能(在我的示例中为“计算机”)以及也属于特定产品的值。
所以我应该得到类似的东西 apple imac - 处理器 - intel i5, 尼康 - 缩放 - 12Mpx
我怎样才能进行这个查询,最好放在哪个模型中??
这是我在 phpmyadmin 中测试过的查询
SELECT `features`.*, `product_features`.`value`
FROM (`features`)
LEFT JOIN `product_features` ON `features`.`feature_id`=`product_features`.`feature_id`
WHERE `features`.`category_id` = 1
WHERE `product`.`product_id` = 1 // without this, it returns feature_id, feature_name, category_id and feature_value collumns, but I also want to specify from wich product
【问题讨论】:
标签: php mysql codeigniter database-schema