mysql - php做商城多属性、多价格、多颜色参数,如何设计?

WBOY
Release: 2016-06-06 20:07:41
Original
1772 people have browsed it

用thinkphp做一个商城

需要有多规格、多价格、多颜色参数,像淘宝购物详情里面的那样

这个数据库字段、和程序如何设计?

然后如何进行读取,请大神给指导哈

回复内容:

用thinkphp做一个商城

需要有多规格、多价格、多颜色参数,像淘宝购物详情里面的那样

这个数据库字段、和程序如何设计?

然后如何进行读取,请大神给指导哈

可以把表设计如下:

商品表

商品 id 商品名称
1 iPhone
2 黄瓜

商品属性表

商品 id 规格 颜色 价格
1 16g 白色 4999
1 32g 白色 5499
2 1

对于你现在自己练手项目,最适用就是这种设计了.
不过此种设计针对商品的属性一定或少的情况下适用,如果属性较多,那么就要增加属性字段,而且有的商品未必用到了这个属性,造成浪费,导致属性表不变扩大.例如商品2黄瓜.
可以变成如下设计:

属性表

属性 id 属性名称
1 规格
2 颜色
3 价格

商品种类表

种类 id 商品 id
a 1
b 1
c 2

商品属性表

商品种类 id 属性 id 属性值
a 1 16g
a 2 白色
a 3 4999
b 1 32g
b 2 白色
b 3 4999
c 4 上海

设计如上,商品黄瓜的属性只会产生一条数据.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!