求php高手写一段简单的代码

请高手写一段php分类数据输出代码。数据库如下:

需要把分类数据像以下形式显示(树形显示):

请各位朋友帮助。一定采纳。
<?php

include("conn.php");
include("head.php");

function list11($pid){
static $deepth=0;
$rs=mysql_query("select * from types where type_p_id='$pid'");
if(mysql_num_rows($rs)<=0){
return ;
}else{
$deepth++;
}
while($row=mysql_fetch_array($rs)){
echo str_repeat(' ',$deepth*2).'|';
echo '+'.$row['type_name'];
echo "<br />";
list1($row['type_id']);
}
$deepth--;
return;
}
?>
代码没错,但什么也没输出来?是什么原因

第1个回答  推荐于2016-05-05
function list11($pid){
static $deepth=0;
$rs=mysql_query("select * from types where type_p_id='$pid'");
if(mysql_num_rows($rs)<=0){
return ;
}else{
$deepth++;
}
while($row=mysql_fetch_array($rs)){
echo str_repeat(' ',$deepth*2).'|';
echo '+'.$row['type_name'];
echo "<br />";
list1($row['type_id']);
}
$deepth--;
return;
}追问

代码没错,但什么也没输出来?是什么原因

追答

一,你要调用list11这个才能运行啊。
二,是我的错,你字段名取的p_id,实际是用的path方式。这是伪无级分类,不需要用递归就能实现

本回答被提问者和网友采纳