function ShowTree($ParentID, $lvl) {
global $link;
global $lvl;
$lvl++;
$sSQL="SELECT * FROM chapters WHERE parent_id = '$ParentID' ";
$result = $link->query($sSQL);
if (mysqli_num_rows($result) > 0) {
echo("<ul class='parent_ul'>\n");
while ( $row = mysqli_fetch_array($result) ) {
$ID1 = $row["id"];
echo("<li class='parent_li'>\n");
echo("<a href=\""."?ID=".$ID1."\">".$row["name"]."</a>"." \n");
ShowTree($ID1, $lvl);
$lvl--;
}
echo("</ul>\n");
}
}
ShowTree(0, 0);