紫悦博客

不进则退,退一步万丈悬崖!

0%

PHP无限级分类读取

get_child(0);

function get_child ($id=0) {
 global $db;
 $id = (int)$id ? (int)$id : 0;
 $sql = "select `cat_id`,`cat_name` from `ecs_category` where `parent_id`='".$id."' ";//查询parent_id 的子类的分类 
 $resource = $db->query($sql);
 echo '<ul>';
 while ($result = $db->fetch_array($resource)) {

  echo "<li>".$result['cat_id']."------".$result['cat_name']."</li>";//输出此类
  get_child ( $result['cat_id']);//继续查询此类的下一子层
 }
 echo '</ul>';

}