您好,我需要一些帮助。 我有3张 table
**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 - 我还不确定是否需要 -)
在我看来,我有一个进行插入/编辑的表单,我想在其中获取特定类别(在我的示例中为“计算机”)的所有功能以及也属于特定产品的值。
所以我应该得到类似的东西 苹果 imac - 处理器 - 英特尔 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
最佳答案
1)产品是你的“主要”实体,所以我会把它放在那里
2) 对所有模型使用 MY_Model 基本模型(您可以在 Google 上搜索 CodeIgniter)
3) 如果您执行 2,您将需要连接表模型,以便可以进行简单的更新
关于php - Codeigniter - 从许多表中获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18653869/