求个递归算法
id name pid
1 AAA 0
2 BBB 1
3 CCC 2
4 DDD 2
5 EEE 0
6 FFF 5
7 GGG 6
得出
AAA
BBB
CCC => 'CCC'
DDD => 'DDD'
EEE
FFF
GGG => 'GGG'
------解决方案--------------------http://bbs.csdn.net/topics/390731721
------解决方案--------------------function tree($pid=0) {
$res = array();
$rs = mysql_query("select * from tbl_name where pid=$pid");
while($row = mysql_fetch_assoc($rs)) {
$res[$row['name']] = ($t = tree($row['id'])) ? $t : $row['name'];
}
return $res;
}
------解决方案--------------------原理是一样的,楼主把1楼链接里的代码修改下就可以满足要求了