By using recursion you are be able...
<?php
$arrayParent = $this->ToDatabase->("SELECT * FROM table WHERE parent_id = 0");
BuildList($arrayParent, 0);
function BuildList($arrayElements, $depth)
{
foreach($arrayElements as $element)
{
echo str_repeat(" ", $depth) . $element["id"];
$depth++;
$totalUnder = $this->ToDatabase->("SELECT * FROM table
WHERE parent_id = " . (int)$element["id"]);
if(count($totalUnder) > 0)
$depth = BuildList($totalUnder, $depth); //$totalUnder fetch to array and step deeper...
return $depth;
}
}
?>