Php Codeigniter-从多个表中获取数据
嗨,我想要些帮助。 我有三张桌子Php Codeigniter-从多个表中获取数据,php,mysql,codeigniter,database-schema,Php,Mysql,Codeigniter,Database Schema,嗨,我想要些帮助。 我有三张桌子 **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
**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
每个表还表示一个模型(因此我有一个产品模型、一个功能模型和一个产品模型,我还不确定是否需要它)
在我看来,我有一个进行插入/编辑的表单,在该表单中,我希望获取特定类别(在我的示例“计算机”中)的所有功能以及也属于特定产品的值
所以我应该买些
苹果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_模型基础模型(您可以在谷歌上搜索CodeIgniter)
3) 如果执行2,则需要联接表模型,以便可以进行简单更新尝试:
select p.*, f.*, pf.* from Products p, Features f, product_features pf where p.product_id = pf.product_id AND pf.feature_id = f.feature_id AND p.category_id = f.category_id
很抱歉,我考虑得不够充分,我已经在使用MY_模型()。我也尝试过使用联接来实现这一点,但是当我尝试传递产品id时,没有得到任何结果。请参阅更新。