you need to try recursivley create tree ,
Try this it will Help you , make your own customising this
function Make_Tree($id,$myroot,$tree)
{
/*
Your Database connection goes here
*/
$query = "SELECT * FROM TABLENAME Where nparent=$id ORDER BY page";
$dresult=mysql_query($query);
$myroot++;
while($drow=mysql_fetch_array($dresult))
{
$mysapce="";
for($i=0;$i < $myroot;$i++)
$mysapce .=" ";
$tree .= $mysapce.$drow[page]."<br>";
$tree = Make_Tree($dcid,$myroot,$tree); // recursively calling function
}
return $tree;
}
$id=0;
$myroot="";
$tree="";
print Make_Tree($id,$myroot,$tree);