function getList($pid=0,&$result=array(),$space=0){ $space=$space+2; $sql="SELECT*FROM deepcate WHERE pid = $pid";判断数据库中是否还有数据的pid等于id的,有的话就属于该id下的子类 $res = mysql_query($sql); while ($row = mysql_fetch_assoc($res)){ $row['catename']=str_repeat(' ',$space).'|--|'.$row['catename']; $result[]=$row; getList($row['id'],$result,$space);// 把ID循环回调传入,判断数据库中是否还有数据的pid等于id的,有的话就属于该id下的子类,就取出来处理,再循环查找下去。 } return $result; }
2017-08-110个赞