Benim yönetim panelinde kullandığım fonksiyonu vereyim sana fikir verir.
function categories_table($id = 0, $string = 0) {
global $database;
$categories = $database->prepare("SELECT * from tm_categories where parentid= :id");
$categories->bindParam(':id', $id, PDO::PARAM_INT);
$categories->execute();
$totalRowCat = $categories->rowCount();
if(0 < $totalRowCat):
foreach($categories as $category):
if($category["parentid"]==0):
$font='style="font-weight:bold !important;"';
$folder = '<img src="img/folder.gif" />';
$extrastring ="8";
else:
$extrastring ="3";
endif;
echo '
<tr>
<td class="text-center">'.$category["id"].'</td>
<td '.@$font.'>'.str_repeat(" ", $string).' '.@$folder.' '.$category["title"].'<br /></td>
<td><small><i>'.$category["description"].'</i></small></td>
<td>
<div class="btn-group">
<button class="btn btn-default btn-sm dropdown-toggle" type="button" data-toggle="dropdown">
İşlem <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="dashboard.php?section=categories&action=categoryedit&id='.$category["id"].'&pid='.$category["parentid"].'">Düzenle</a></li>
<li><a href="dashboard.php?section=categoriess&action=dropcategory&id='.$category["id"].'">Sil</a></li>
</ul>
</div>
</td>
</tr>';
categories_table($category["id"], $string+5);
endforeach;
endif;
}