CREATE TABLE likecate (
id INT UNSIGNED NOT NULL PRIMARY KEY,
path VARCHAR(200) NOT NULL DEFAULT '' COMMENT '全路径',
catename VARCHAR(30) NOT NULL DEFAULT '' COMMENT '分类名',
cateorder INT UNSIGNED NOT NULL DEFAULT 0 COMMENT '排序',
createtime INT UNSIGNED NOT NULL COMMENT '创建时间'
)ENGINE=MYISAM DEFAULT CHARSET=utf8;
INSERT INTO likecate 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','Android手机',0,0),
(7,'1,5','iOS手机',0,0),
(8,'1,5','winphoto手机',0,0),
(9,'1,2,4','色盲手机',0,0),
(10,'1,2,3','大字手机',0,0),
(11,'12','台式机',0,0),
(12,'','电脑',0,0),/*经过一些增删操作,有可能父类id大于子类id*/
(13,'12,11','一体机',0,0),
(14,'12,11','非一体机',0,0),
(15,'12','笔记本',0,0);
CREATE TABLE IF NOT EXISTS `deepcate` (
`id` int(4) NOT NULL,
`pid` int(11) NOT NULL,
`catename` varchar(30) NOT NULL,
`cateorder` int(11) unsigned NOT NULL DEFAULT '0',
`createtime` int(10) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 COMMENT='cms类型表';
--
-- 转存表中的数据 `deepcate`
--
INSERT INTO `deepcate` (`id`, `pid`, `catename`, `cateorder`, `createtime`) VALUES
(1, 0, '新闻', 0, 0),
(2, 0, '图片', 0, 0),
(3, 1, '国内新闻', 0, 0),
(4, 1, '国际新闻', 0, 0),
(5, 3, '北京新闻', 0, 0),
(6, 4, '美国新闻', 0, 0),
(7, 2, '美女图片', 0, 0),
(8, 2, '风景图片', 0, 0),
(9, 7, '日韩明星', 0, 0),
(10, 9, '日本AV', 0, 0);
输出下拉菜单
查询结构代码
数据表结构
面包屑分类
<?php require_once('./db.php'); //面包屑类型分类 $id = isset($_GET['id'])?$_GET['id']:false; if (!$id){ echo '<script>window.location.href="./03.php?id=1"</script>'; }else{ function getCatePath($id=1,&$arr = []){ $func = __FUNCTION__; if (!$id){ dir('不能为0'); } $sql = "select * from deepcate where id=$id"; $res = mysqli_fetch_assoc(query($sql)); $arr[] = $res; if ($res['pid']){ $func($res['pid'],$arr); } return $arr; } $arr = array_reverse(getCatePath($id)); if (empty($arr[0]['id'])){ die('id无效'); }else{ foreach ($arr as $key=>$val){ echo "<a href='./03.php?id={$arr[$key]['id']}'>{$arr[$key]['catename']}</a>".">"; } } }
初始化数据库
<?php header("Content-type: text/html; charset=utf-8"); $db_name = 'infiniteclass'; $host = 'localhost'; $user = 'root'; $password = '123456'; $link = null; //初始化数据库连接 function initDB($db_name,$host,$user,$password){ global $link; $link = mysqli_connect($host,$user,$password,$db_name); if (!$link){ die('数据库链接失败'); } mysqli_query($link,'set names utf8'); } //查询函数 function query($str){ global $link; $res = mysqli_query($link,$str); if (!$res){ return '查询失败'; }else{ return $res; } } initDB($db_name,$host,$user,$password);
递归分类原理
递归笔记
无限级 常见的几种实现