I have This MySql
table for put multiple news categories(parent/child) :
ID | NAME | PARENTID | DESC |
1 | LINUX | 0 | NULL |
Use recursion! Note: the code below is not safe for cyclic graphs (nodes may not be ancestors of themselves)!
printChildren($items,0);
function printChildren(array $items, $parentId){
foreach($items as $item){
if($item['parent']==$parentId){
print '<li>';
print $item['label']; //or whatever you want about the current node
print '<ul>';
printChildren($items, $item['id']);
print '</ul></li>';
}
}
}