一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

php无限级分类实例三

时间:2011-08-26 编辑:简简单单 来源:一聚教程网

数据库教程


--
-- Table structure for table `category`
--
CREATE TABLE IF NOT EXISTS `category` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`catpath` varchar(255) DEFAULT NULL,
`name` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=11 ;
--
-- Dumping data for table `category`
--
INSERT INTO `category` (`id`, `catpath`, `name`) VALUES
(1, '0', '网站首页'),
(2, '0-1', 'Linux OS'),
(3, '0-1', 'Apache服务器'),
(4, '0-1', 'MySQL数据库'),
(5, '0-1', 'PHP脚本语言'),
(6, '0-1-2', 'Linux 系统教程'),
(7, '0-1-2', 'Linux 网络技术'),
(8, '0-1-2', 'Linux 安全基础'),
(9, '0-1-2-7', 'Linux LAMP'),
(10, '0-1-3-10', 'apache Server');

php教程代码

$conn = mysql教程_connect ( 'localhost', 'root', '' );
mysql_select_db ( 'test', $conn );
mysql_query ( 'set names UTF8' );
$sql = "select id,concat(catpath,'-',id) as abspath,name from category order by abspath";
$query = mysql_query ( $sql );
while ( $row = mysql_fetch_array ( $query ) ) {
/**
* 第一种展示方法
*/
/*$space = str_repeat ( ' ', count ( explode ( '-', $row ['abspath'] ) ) - 1 );
echo $space . $row ['name'] . '
';*/
/**
* 第二种展示方法
*/
$space = str_repeat ( ' ', count ( explode ( '-', $row ['abspath'] ) ) - 1 );
$option .= '';
}
echo '';

效果

热门栏目