dpzo13732 2011-11-08 14:14
浏览 7
已采纳

PHP + MySQL中的前端产品变体?

I'm doing a webshop, and every product can have several variants.

All variants are actually their own product. The SKU is different per product, but the productnumber is the same for all variants of "one product".

The variant combinations is held in a seperate table called variantvalues. In there is the product SKU, fieldname and fieldvalue.

Let's say I have 3 products. SKUs: 0505002699/SB/M, 0505002699/SC/L, and 0505002699/SC/M.

All products have the same productnumber; 0505002699.

The products have the following fields: Color, Size.

These are the values for each product:

0505002699/SB/M

Color: Black

Size: Small

0505002699/SC/L

Color: Blue

Size: Medium

0505002699/SC/M

Color: Red

Size: Small


Anyone with a clue on how I can loop that front end? Final result should be something like: http://i.stack.imgur.com/rAxeG.png

The problem (for me) is to figure out how to list the possible "configurations".

Anyone?

  • 写回答

2条回答 默认 最新

  • dougan6402 2011-11-08 14:24
    关注

    Just a quick thought of implementation:

    If the "configurations" are variable for each product:

    Extra tables:

    size
      - code
      - descr
    

    fe:

    S - Small
    M - Medium
    

    And then a table between product and size:

    product_size
       - product_id
       - size_code
    

    fe:

    1 - S
    1 - M
    2 - S
    ...
    

    For the color:

    product_color
       - product_id
       - color
    

    fe:

    1 - #FFFFFF
    1 - #000000
    2 - #000000
    ...
    

    Then you can select all options for each product by product_id.

    fe:

    SELECT color FROM colors WHERE product_id = $product_id;
    SELECT size_code FROM product_size WHERE product_id = $product_id;
    

    EDIT: wow i misread a part of your question, sorry

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

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程