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条)

报告相同问题?

悬赏问题

  • ¥25 关于##爬虫##的问题,如何解决?:
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误