查看文件: showroot.bak.php
大小: 3.14 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"; $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); }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) { $hostName = "localhost"; $username = "root"; $password = "loskyoc"; $dbname = "newskybni"; $dblink = mysqli_connect($hostName, $username, $password, $dbname) or die(mysqli_error()); global $chkid; global $showrefer ; $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){ while($value = mysqli_fetch_assoc($result)){ $id = $value['id'] ;//$value['id']; $row1[$id]['id'] = $value['id']; // if($showrefer){ $row1[$id]['name'] = $value['name'].','.$value['id'] ;} if($showrefer){ $row1[$id]['name'] = $value['id'].$value['name'] ;} // if($showrefer){ $row1[$id]['name'] = $value['name'] ;} else{ $row1[$id]['name'] = $value['name']; } $row1[$id]['parentid'] = $value['parentid']; //$row1[$id]['tag'] = count(membersTree($value['id'])); // $tag = count(membersTree($value['id'])); $sql2 = sprintf("SELECT id from usertree WHERE parentid='%s' ",$value['id']); $result2 = mysqli_query($dblink, $sql2); $totalRows2 = mysqli_num_rows($result2); $tag =$totalRows2 ; // if($row1[$id]['tag'] >0){ if($tag >0){ $row1[$id]['children'] = array_values(membersTree($value['id'])); } } } return $row1 ; mysqli_close($dblink); } removeKey($data, 'id'); removeKey($data, 'parentid'); $str1 = json_encode(array_values($data)); $str1 =mb_substr($str1,1,-1); echo $str1; mysqli_close($dblink); ?>
保存
取消
返回文件列表