2012-10-03 35 views
3

我正在开发产品数据库,为我的尺寸创建一个单独的表PRODUCT_SIZE(id,sizetext)mysql最好的方式来管理产品尺寸

例如, (1,'小'),(2,'大'),(3,'超大'),...

我提供这些尺寸列表为复选框,当添加产品时,所有可能的尺寸都可以针对当前产品进行选择。

例如选择T恤,小号和大号尺码。

这些2尺码可用于反对每个新购买的库存条目。 现在我才知道,可以有不同尺寸的单位,有些物品可以是英寸,一些是千克,一些是米。

我心中有一个改变的溶液: 改变表

PRODUCT_SIZE(id,sizetext, UNitType);

现在它可以是:(1, '5', 'KG'),(2,'10' ,” KG'),(3,'2.5','英寸'),...

是否有更好的方法,建议?

回答

0

为什么不把所有的下拉选项都放在应用程序作用域变量中,而不是为此创建一个单独的表?然后,您可以直接将该数据作为字符串添加到产品中的字段中,并以编程方式处理不同的选项/单位。

+0

尺寸可从管理面板添加/删除。对于未来的产品,管理员可以输入与产品相关的尺寸。 –

+0

啊,如果尺寸是动态的,那么你可能会更好地使用你的方法。 –

2

看起来你正在将“衣服尺寸”,“重量”和“长度”强制为一个“尺寸”属性。

尝试这些表:

product (product_id, name) 
    "Nike t-shirt" 

    attribute_group (attribute_group_id, name) 
    "Shirt size", "Weight", "Length", etc. 

    attribute_value (attribute_value_id, attribute_group_id, name) 
    "Shirt size" would have rows for "Small", "Large", etc. 

    product_attribute (product_id, attribute_value) 
    "Nike t-shirt" is "Large" 

添加 “显示顺序” 来ATTRIBUTE_VALUE,太(所以 “小”,可之前 “大” 显示)。

对于其他属性也这样做。

我已经为一个生产网站做了这个,我认为它运作良好。

祝你好运。

0

我做了一个存储衣服的数据库,其中的尺寸是几种类型。一篇文章的尺寸是xs s m l其他是 26 27 28 29 30等等。 我决定这样做:

# on one side in the script i define size types and names; 
$sizeTypes[1] = [XS, S, M, L]; 
$sizeTypes[2] = [29, 30, 31, 32]; 
#The and so on 
#and on the other side in the database, there are just two columns 

size_type_id(int) | size_qty | 

# so if I have one article with 3 pieces of size S 2 pieces of size M and 5 pieces of size L the database will store: 
size_type_id| size_qty  | 
1   |0:0;1:3;2:2;3:5| 

然后在脚本中,我只是让1型的0是XS 1型1型的S 2的翻译呢2是31等

相关问题