dongsui3297 2013-09-06 09:01
浏览 53
已采纳

too long

Hi I 'd like some help please. I have 3 tables

**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

Each table also represents a model (so i have a product_model, feature_model and a product_feature_model -which i'm not sure yet if its needed-)

In my view I have a form in which i do inserting/editing, in which I want to fetch all the features of the specific category (in my example 'computers') and the values that also belong to the specific product.

So I should get something like apple imac - processor - intel i5, nikon - zoom - 12Mpx

How can I make this query and in which model is it better to put into??

Here's the query i've tested in 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
  • 写回答

2条回答 默认 最新

  • dongshaoxiong0012 2013-09-06 09:10
    关注

    1) Product is your "primary" entity, so I would put it there

    2) Use a MY_Model base model (you can Google it for CodeIgniter) for all your models

    3) If you do 2, you'll want the join table model so you can make simple updates

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥85 maple软件,solve求反函数,出现rootof怎么办?
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题