Table of Contents
mysql - php做商城多属性、多价格、多颜色参数,如何设计?
Jun 06, 2016 pm 08:07 PM
mysql
php
Mall
用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 | 上海 |
设计如上,商品黄瓜的属性只会产生一条数据.
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

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How to fix mysql_native_password not loaded errors on MySQL 8.4
