How can using php mysql create a dynamic tree for this tables
tbl_folder
db_id db_foldername
1 accounting
2 hr
3 it
tbl_subfolder
db_id db_folderid db_subfoldername
1 1 xxx
2 1 yyy
3 2 zzz
tbl_childsubfolder
db_id db_subfolderid db_childsubfoldername
1 1 ffff
2 2 llll
tbl_subchild
db_id db_childsubfolderid db_subchildname
1 1 eee
2 1 ppp
accounting
xxx
- fff
- eee
- ppp
- fff
yyy
- lll
hr
- zzz
it
include("include/connect.php"); --SELECT-- $name"; }
?>
if(isset($_POST['add'])){ $foldername=$_POST['txt_name']; $select=$_POST['txt_select'];echo $select; $explod=explode("-",$select); $path=$explod['0'].';'.$explod['1']; if($path==";"){$path="";} $parent_id=$explod['1']; if($foldername==""){echo"enter a name";} else{ $insert_query=mysqli_query($conn,"insert into tbl_folders(parent_id,path,name)values('$parent_id','$path','$foldername')")or die(mysqli_error($conn)); header("location:index.php"); } } $sql=mysqli_query($conn,"select * from tbl_folders where parent_id='0'")or die(mysqli_error($conn)); while($row=mysqli_fetch_array($sql)){ $name=$row['name']; $id=$row['db_id']; echo $name;echo"<br/>"; $sqli=mysqli_query($conn,"select * from tbl_folders where parent_id='$id'")or die(mysqli_error($conn)); while($row=mysqli_fetch_array($sqli)){ $name=$row['name']; $id=$row['db_id']; $path=$row['path']; $x=explode(";",$path);echo $path;echo"<br/>"; $pa=$x['1']; echo $name;echo"<br/>"; $sqli=mysqli_query($conn,"select * from tbl_folders where parent_id='$id' and path='$pa'")or die(mysqli_error($conn)); while($row=mysqli_fetch_array($sqli)){ $name=$row['name']; $id=$row['db_id']; $path=$row['db_path']; echo $name;echo"<br/>";} } }