<?php
header("content-type:text/html;charset=utf8");
$link = mysqli_connect('localhost','username','password','test');
mysqli_set_charset($link, "utf8");
if (!$link) {
die("连接失败:".mysqli_connect_error());
}
function getList($pid=0,&$result=array(),$space=0){
global $link;
$space=$space+2;
$sql="select * from class where pid = $pid";
$res = mysqli_query($link,$sql);
while ($row = mysqli_fetch_assoc($res)){
$row['title']=str_repeat(' ',$space).'|-- '.$row['title'];
$result[]=$row;
getList($row['id'],$result,$space);
}
return $result;
}
$rs=getList();
print_r($rs);
?>