在数据库中存储产品颜色的最佳方法 [英] Best way to store product colors in a database
问题描述
我正在在线珠宝商店网站上工作。要求之一是,从后端可以为单件珠宝选择一种或多种颜色,以便用户能够仅对例如绿色的物品进行分类/查看。
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:
- 产品表(已经存在)
- 颜色表:每个字段都有一个与产品相匹配的颜色
- 表,并带有颜色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屋!