php进阶 无限极分类

通过排序查找出分类
数据库
CREATE TABLE `infinite_classify1` (
  `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
  `catpath` varchar(100) NOT NULL,
  `title` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;

数据库概览
php进阶 无限极分类

php进阶 无限极分类
程序代码
<?php
header("content-type:text/html;charset=utf-8");
mysql_connect('localhost','root','910729') or die('链接数据库失败');
mysql_set_charset('utf8');//设定mysql客户机(php)与mysql服务器之间通信的编码
mysql_select_db('test');
$sql="select id,concat(catpath,'-',id) as abspath,title from infinite_classify1 order by abspath,id";
$result = mysql_query($sql);
//$arr=array();
//$i=0;
//while ($val=mysql_fetch_assoc($result)){
//    $arr[$i]=$val;
//    $i++;
//}

while ($row=mysql_fetch_assoc($result)){
    $space = str_repeat('&nbsp;&nbsp;',count(explode('-',$row['abspath']))-1);
    echo $space.$row['title'].'<br>';
}
echo '<pre>';
print_r($arr);


php进阶 无限极分类