gpt4 book ai didi

php - Codeigniter - 从许多表中获取数据

转载 作者:行者123 更新时间:2023-11-30 01:20:01 25 4
gpt4 key购买 nike

您好,我需要一些帮助。我有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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com