查看文件: showchildrenphp.php
大小: 5.64 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); } } } } 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 > ".$ppid."<==>".$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'];} // $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 $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"]'; } */ $findme='"name":"'; for($cid=1;$cid<24002;$cid++){ //$id =1; $chkid=1; $level='' ; $data = membersTree($cid,1); removeKey($data, 'id'); removeKey($data, 'parentid'); //removeKey($data, 'children'); $str1 = json_encode(array_values($data)); $str1 =mb_substr($str1,1,-1); $pos=true; //echo $str1. " << <br>" ; ; //echo $i.'>>>>>'; $str3=''; $cc=0; while ($pos) { $pos = strpos($str1, $findme,0); if ($pos>0){ $str1=substr($str1,$pos+8); $pos2 = strpos($str1, '"',0); $str2=substr($str1,0,$pos2); if($cc>0)( $str3 .= $str2. ","); $cc++; } } $str3=substr($str3,0,-1); $a=explode(",",$str3); $b1=array(); for($i=0;$i<12;$i++){ $b[$i]=isset($a[$i])?$a[$i]:"0"; $b1[$i]='0'; } $fck='N'; if(count($a)==12){ $b1[0]=$b[0]; $b1[3]=$b[1]; $b1[4]=$b[2]; $b1[5]=$b[3]; $b1[1]=$b[4]; $b1[6]=$b[5]; $b1[7]=$b[6]; $b1[8]=$b[7]; $b1[2]=$b[8]; $b1[9]=$b[9]; $b1[10]=$b[10]; $b1[11]=$b[11]; $b=$b1; $fck='Y' ;} $upsql = sprintf("update usertree set f1='%s',f2='%s',f3='%s',f4='%s',f5='%s',f6='%s',f7='%s',f8='%s',f9='%s',f10='%s',f11='%s',f12='%s',fck='%s' where id='%s'", $b[0],$b[1],$b[2],$b[3],$b[4],$b[5],$b[6],$b[7],$b[8],$b[9],$b[10],$b[11],$fck,$cid); // 1 2 3 //$data=array(); mysqli_query($dblink,$upsql); echo $str3." << ".count($a)."<br>" ; } //removeKey($data, 'id'); //removeKey($data, 'parentid'); //$str1 = json_encode(array_values($data)); //$str1 =mb_substr($str1,1,-1); //echo $str1; mysqli_close($dblink); ?>
保存
取消
返回文件列表