zoukankan      html  css  js  c++  java
  • php商城数据库的设计 之无限分类

    商品分类,使用无限分类

    即:

    -------如何创建数据表

      

     pid---父级分类id,如果是顶级分类则为0

    path---1,用户分类的排序

    排序示例:

    实现逻辑:获取type表的所有分类,order by path ,   得到了type列表,然后path有几个逗号就加几个---,

    这样,父级分类下就是子级分类,子级分类下是孙级分类,分类得到了有效的排序。

      2,点击父级分类,展示所有它和它的所有子级分类所辖的商品

    实现逻辑: 子级分类的path  like %父级分类的path%,再通过where的or语句(where (id=1 or id=2) ),可以实现点击父级分类,显示它和它所有子级分类的商品

    level---表示当前分类是几级分类,一般用于展示

    sql代码

    商品表
    create table goods(
      id int unsigned auto_increment primary key,
      goods_type_id int unsigned not null default 0 comment '商品分类外键',
      brand_id int unsigned not null default 0 comment '品牌外键',
      name varchar(100) not null default '' comment '商品名称',
      title varchar(255) not null default '' comment '商品标题',
      img varchar(150) not null default '' comment '商品缩略图',
      
      old_price decimal(10,2) unsigned not null default 0 comment '原价',
      pricr decimal(10,2) unsigned not null default 0 comment '售价',
      stock int  unsigned not null default 0 comment  '库存',
      warnstock int unsigned  not null default 0 comment '预警库存' ,
      
      
      status tinyint unsigned not null default 0  comment '商品状态 ,1-在售  0-下架',
    
      sell_num int unsigned not null default 0 comment '销量',
      
      detail varchar(999) not null default '' comment '商品详情',
      
      create_time int(10) unsigned not null default 0  comment '商品创建时间',
      update_time int(10) unsigned not null default 0 comment '商品更新时间'
      
    )
    
    
    
    
    无限分类
    create table goods_type(
        id int unsigned auto_increment primary key,
        name varchar(20) not null default '' comment '分类名',
        pid int unsigned not null default 0  comment '父级分类id(0:顶级分类)',
        path varchar(20) not null  default '' comment '分类路径(排序)',
        level int unsigned not null default 0 comment '分类等级(1:顶级分类)'
    ) 
    
    品牌表
    create table brand(
    id int unsigned auto_increment primary key,
    name varchar(20) not null default '' comment '品牌名',
    logo_img varchar(150) not null default '' comment '品牌logo图',
    info varchar(255) not null default '' comment '品牌简介',
      create_time int(10) unsigned not null default 0  comment '品牌创建时间',
      update_time int(10) unsigned not null default 0 comment '品牌更新时间'
    )

    goods: 

    brand:

    goods_type:

  • 相关阅读:
    关于字符编码,你所需要知道的(ASCII,Unicode,Utf-8,GB2312…)
    Python基础一
    windows环境下 安装python2和python3
    Python数据类型及常用操作
    Python流程控制
    Python用户交互以及数据类型
    Python介绍以及Python环境搭建
    multiprocessor(下)
    multiprocessor(中)
    multiprocess(上)
  • 原文地址:https://www.cnblogs.com/cl94/p/9593273.html
Copyright © 2011-2022 走看看