php+mysql实现的一个简单分类。php
数据库建一张test表,分别设置4个字段,id(number)、name(varchar)、pid(varchar)、path(varchar)mysql
order by //mysql函数:排序(默认升序ASC)sql
concat //mysql函数:链接字符串数据库
substr_count //php函数:统计字符串个数函数
str_pad //php函数:填充fetch
//使用order by排序、concat合并字符串。 $_select="SELECT * FROM concat order by concat(path,id)"; $_result=mysql_query($_select) or die (mysql_error()); while($_row=mysql_fetch_assoc($_result)){ //统计逗号的个数 $_len=substr_count($_row['path'],',')-1; //填充空格 $_m=str_pad("",$_len*6*4," "); echo $_m.'-'.$_row['name'];