目前我正在使用递归函数以文本格式显示数据,例如..
Food
Fruit
Red
Apple
Yellow
Banana
Meat
Beef
Pork
我正在使用以下代码来显示此文本
function display_children($parent, $level) {
$result = mysql_query('SELECT * FROM category '.
'WHERE parant_id="'.$parent.'";');
while ($row = mysql_fetch_array($result)) {
echo str_repeat(' ',$level).$row['name']."\n";
display_children($row['id'], $level+1);
}
}
display_children(0,0);
<ul>
<li>
但现在我想在菜单中显示上述文本
<ul>
<li>Food
<ul>
<li>Fruit
<ul>
<li>Red
<ul>
<li>Apple</li>
</ul>
</li>
<li>Yellow
<ul>
<li>Banana</li>
</ul>
</li>
</ul>
</li>
<li>Meat
<ul>
<li>Beef</li>
<li>Pork</li>
</ul>
</li>
</ul>
</li>
</ul>
所有数据都以以下格式存储在表中
+----+-----------+--------+
| id | parant_id | name |
+----+-----------+--------+
| 1 | 0 | Food |
| 2 | 1 | Fruit |
| 3 | 1 | Meat |
| 4 | 2 | Red |
| 5 | 2 | Yellow |
| 6 | 4 | Apple |
| 7 | 5 | Banana |
| 8 | 3 | Beef |
| 9 | 3 | Pork |
+----+-----------+--------+
请帮我以<ul>
<li>
格式显示整个数据
谢谢