树形数组的递归遍历


include_once ("inc/auth.inc.php");

function tree($parentid = 0) {
 /*获取递归的数据*/
 $sql = "select * from file_sort where sort_parent = $parentid";
 $sql1="select * from file_sort where sort_parent = $parentid order by sort_no asc";
 if($parentid ==0){
  $rs = mysql_query ( $sql,TD::conn() );
 }else{
  $rs = mysql_query ( $sql1,TD::conn() );
 } 
 
 echo ("

    ");
     while ( $ra = mysql_fetch_row ( $rs ) ) {  /* 循环输出是树节点 */
      ?>
         echo ('
      ' . $ra [0] . '
    ');
      ?>
     
     
      
      
      /* 递归调用 -循环输出子节点*/
      tree ( $ra [1] );
     }
     echo ("
");
}
tree ();
?>

你可能感兴趣的:(php)