zoukankan      html  css  js  c++  java
  • php无限极分类

    <?php
    
    //递归无限极分类
    CREATE TABLE `deepcate` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `pid` int(11) DEFAULT NULL,
      `catename` varchar(11) DEFAULT NULL,
      `cateorder` int(11) DEFAULT NULL COMMENT '排序字段',
      `createtime` int(10) DEFAULT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
    
    INSERT INTO `deepcate` VALUES (1,0,'新闻',0,0),(2,0,'图片',0,0),(3,1,'国内新闻',0,0),(4,1,'国外新闻',0,0),(5,2,'风景图片',0,0),(6,2,'美女图片',0,0),(7,4,'美国新闻',0,0),(8,3,'广东新闻',0,0),(9,5,'海滩风景',0,0),(10,6,'模特风采',0,0);
    
    
    function getTree($list,$pid=0,$level=0 ){
        static $array=array();
        foreach($list as $key=>$value){
            if($value['auth_pid']==$pid){
                $value['level']=$level;
                $array[]=$value;
                getTree($list,$value['auth_id'],$level+1);
            }
        }
        return $array; 
    }
    getTree($list);
    
    //全路径无限极分类
    CREATE TABLE `fullpath` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `path` varchar(255) DEFAULT NULL COMMENT '全路径',
      `catename` varchar(255) DEFAULT NULL COMMENT '分类名称',
      `cateorder` int(11) DEFAULT NULL COMMENT '排序',
      `createtime` int(11) DEFAULT NULL COMMENT '创建时间',
      PRIMARY KEY (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
    
    
    INSERT INTO `fullpath` VALUES (1,'','手机',0,0),(2,'1','功能手机',0,0),(3,'1.2','老人手机',0,0),(4,'1.2','儿童手机',0,0),(5,'1','智能手机',0,0),(6,'1.5','IOS手机',0,0),(7,'1.5','WinPhoto手机',0,0),(8,'1.5','android手机',0,0),(9,'1.2.4','色盲手机',0,0),(10,'1.2.3','大字手机',0,0);
    
    
    //必须用.进行连接  mysql order by 排序 规则
    $data = 'select id,path,catename,concat(path,'.',id) as full from `fullpath` order by full asc';
    foreach($data as $v ){
         $data[$k]->level=count(explode('.',trim($v->full,'.')));
    }
  • 相关阅读:
    不可或缺 Windows Native (15)
    不可或缺 Windows Native (14)
    不可或缺 Windows Native (13)
    不可或缺 Windows Native (12)
    不可或缺 Windows Native (11)
    不可或缺 Windows Native (10)
    不可或缺 Windows Native (9)
    不可或缺 Windows Native (8)
    不可或缺 Windows Native (7)
    不可或缺 Windows Native (6)
  • 原文地址:https://www.cnblogs.com/mengor/p/7823463.html
Copyright © 2011-2022 走看看