在数据库中存储产品颜色的最佳方法 [英] Best way to store product colors in a database

查看:242
本文介绍了在数据库中存储产品颜色的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在在线珠宝商店网站上工作。要求之一是,从后端可以为单件珠宝选择一种或多种颜色,以便用户能够仅对例如绿色的物品进行分类/查看。

I am working on an online jewelry store website. One of the requests is that from the back end a color/colors can be chosen for a single piece of jewelry so that users would be able to sort/view only items that are for instance green.

将其存储在数据库中的最佳方法是什么?应该使用3个表格来完成此操作吗:

What is the best way to store this in a database? Should this be done with 3 tables:


  1. 产品表(已经存在)

  2. 颜色表:每个字段都有一个与产品相匹配的颜色

  3. 表,并带有颜色id

是这是正确的方法吗?我正在使用php和mysql,但我认为这只是一个非常标准的数据库问题。

Is this the correct way to do it? I am using php and mysql but I think this is just a pretty standard database question.

推荐答案

是的,在表之间具有多对多关系的解决方案听起来很适合您的情况。然后,您可以轻松地联接表以从ID中获取信息。

Yes, your solution with a many-to-many relationship between tables sounds good for your case. You can then easily JOIN the tables to get information out of the IDs.

这篇关于在数据库中存储产品颜色的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆