001002003004005006007008009010011012013014015016017018019020021022023024025026027028029030031032033034035036037038039040041042043044045046047048049050051052
<?php $id = $_REQUEST['id']; if(empty($id)) $id=0; $query = "select id, substring_index(getpath_v2(id),'|',-1) as path from gubun_tree_v2 where id=$id"; // $result=mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";} $matched=mysqli_fetch_assoc($result); $query = "select a.id,a.parent,a.sub_seq,a.name,a.linked_num,@path:=getpath_v2(a.id), @temp:=substring_index(substring_index(@path,'|',2),'|',-1) as pre_ord, (char_length(@temp)-char_length(replace(@temp,'.','')) + 1) as depth, substring_index(@path,'|',-1) as path ,count(b.id) as sub_cnt from gubun_tree_v2 a left join gubun_tree_v2 b on a.id=b.parent where a.id<>0 and a.parent in (".$cur_path.") group by a.id order by pre_ord" ; $result=mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";} $prev=1; $i=0; while ( $matched = mysqli_fetch_assoc($result) ) { $set[] = $matched; if ($id == $matched[id]) $cur_row = $matched; if ( strpos(','.$cur_path.',',$matched[parent]) !== false) { $per_parent_rows[$matched[parent]][] = $matched; } $i=$i+1; } ?>