php+mysql无限级分类

无限级分类、、、但是效率不是最好的。。。大家有没有更快更好的效率的代码呢?

用递归等到类别多的时候就会影响效率了!

求分享!

class.sql

--
-- 表的结构 `class`
--
set names utf8;
CREATE TABLE `class` (
  `id` int(10) NOT NULL auto_increment,
  `name` varchar(250) character set utf8 default NULL,
  `classid` int(10) default NULL,
  `sort` int(10) not null default '0',
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=11 ;

--
-- 导出表中的数据 `class`
--

INSERT INTO `class` (`id`, `name`, `classid`, `sort`) VALUES
(1, '中国', 0, 1),
(2, '广西', 1, 1),
(3, '桂林', 2, 2),
(4, '广东', 1, 2),
(5, '北京', 1, 3),
(6, '东莞', 4, 10),
(7, '南宁', 2, 10),
(8, '阳朔', 3, 10),
(9, '柳州', 2, 10),
(10, '广州', 4, 10);


index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无限级分类</title>
<style type="text/css">
* {
	padding:0;
	margin:0;
}
body {
	font: 14px Arial, Helvetica, sans-serif;
	overflow-x: hidden;
	overflow-y:auto;
	color:#444444;
}
#main {
	width:600px;
	margin:20px auto;
}
#main table{
	margin-top:8px;
	width:100%;
	border-collapse:collapse;
	border-spacing:0px;
	BACKGROUND-COLOR: #EFEFEF;
	border:0px;
}
#main table td{
	line-height:20px;
	border:1px solid #FFF;
	padding:5px;
}
#main table thead td {
	background:#C6C6C6;
	FONT-SIZE:15px;
	text-align:center;
	line-height:23px;
	font-weight:bold;
}
.input {
	border-top: 1px inset;
	border-left: 1px inset;
	padding:2px 3px;
}
</style>
</head>
<body>
<div id="main"> <a href="?action=">分类列表</a> <a href="?action=add">添加分类</a>
  <?php

$mysql = new mysql_Class('localhost','root','');

$mysql -> select_db('test');

switch($_GET['action']){
	case 'add':
		$class_arr=array();
		$sql = "
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值