查看文件: showroot.php
大小: 3.96 KB
类型: application/octet-stream
<?php function removeKey(&$array, $key) { if (is_array($array)) { if (isset($array[$key])) { unset($array[$key]); } if (count($array) > 0) { foreach ($array as $k => $arr) { removeKey($array[$k], $key); } } } } $hostName = "localhost"; $username = "root"; $password = "loskyoc"; $dbname = "newskybni"; $level='' ; //$levelnow='' ; $dblink = mysqli_connect($hostName, $username, $password, $dbname) or die(mysqli_error()); $id =1; $chkid=1; $parentKey = isset($_GET['id'])?$_GET['id']:1 ;//$_SESSION['login_addr']; //$parentKey = isset($_GET['id'])?$_GET['id']:1 ;//$_SESSION['login_addr']; $showrefer=true; //if($parentKey==1){ $showrefer=true;} $sql = "SELECT * FROM usertree" ; //$data=array(); $result = mysqli_query($dblink, $sql); if(mysqli_num_rows($result) > 0) { $data = membersTree($parentKey,$id); }else{ $data='["id"=>"0","name"=>"No Members present in list","text"=>"No Members is present in list","nodes"=>[]]'; // $data='["name"=>"No Members present in list"]'; } function membersTree($parentKey,$ppid) { $hostName = "localhost"; $username = "root"; $password = "loskyoc"; $dbname = "newskybni"; $dblink = mysqli_connect($hostName, $username, $password, $dbname) or die(mysqli_error()); global $chkid; global $showrefer ; global $level; $setmaxleve=3; $levelnow=''; $row1=array(); if($chkid==1){ $sql = 'SELECT id, name,parentid from usertree WHERE id="'.$parentKey.'"'; } else{ $sql = 'SELECT id, name,parentid from usertree WHERE parentid="'.$parentKey.'"'; } $chkid++; $result = mysqli_query($dblink, $sql); $totalRows = mysqli_num_rows($result); if($totalRows>0){ if ($chkid>2){ $level .= $parentKey.',' ; // echo "lll > ".$parentKey."<br>";//$parentKey;//$parentKey // echo "l > ".$level."==p>".$parentKey.'==id>'.$id."<br>";//$parentKey $a=explode(',',$level); $c=-1; $level2=''; for($i=0;$i<count($a)-1;$i++){ // echo " FF1 > ".$id."<==>".$a[$i]."<br>" ; if ($c<0){ $level2.= $a[$i].','; } if( $ppid==$a[$i]) { $c=$i; $level2.= $parentKey.','; // echo " FFFFFFF > ".$c." add :".$parentKey ."<br>";//$parentKey;//$parentKey // echo " ref > ".$level2."==p>".$parentKey.'==id>'.$id."<br>";//$parentKey break; } } $level=$level2; $levelnow=$level2; // echo " ref2 > ".$level."==p>".$parentKey.'==id>'.$id."<br>";//$parentKey } $a1=explode(",",$levelnow); while($value = mysqli_fetch_assoc($result)){ $id = $value['id'] ;//$value['id']; $row1[$id]['id'] = $value['id']; if($showrefer){ $row1[$id]['name'] = $value['id'].$value['name'] ;} //.'-'.$levelnow ; else{ $row1[$id]['name'] = $value['name']; } $row1[$id]['parentid'] = $value['parentid']; if($setmaxleve>count($a1)){ $sql2 = sprintf("SELECT id from usertree WHERE parentid='%s' ",$value['id']); $result2 = mysqli_query($dblink, $sql2); $totalRows2 = mysqli_num_rows($result2); $tag =$totalRows2 ; if($tag >0){ $row1[$id]['children'] = array_values(membersTree($value['id'],$value['parentid'])); } // end $tag } //end max count children } // end while } // end $totalRows>0 return $row1 ; mysqli_close($dblink); } // end function removeKey($data, 'id'); removeKey($data, 'parentid'); $str1 = json_encode(array_values($data)); $str1 =mb_substr($str1,1,-1); echo $str1; mysqli_close($dblink); ?>
保存
取消
返回文件列表