网上找的php无限级分类,但是这个是嵌在html中的,请问在phplib模板中如何输出到html呢?
function sort_s($id){ $sql="select * from article_cat where parent_id=".$id;
$result =mysql_query($sql); while($row = mysql_fetch_array($result)){
$rid=explode(",",$row['depth']);
$i=count($rid);
$n = str_pad('',$i,'-',STR_PAD_RIGHT);
$n = str_replace("-"," ",$n); if($row['parent_id']==0){ echo "<option value=\"".$row['cat_id']."\" style='background:#ccc' >".$row['cat_name']."</option>\r\n";
}else{
echo "<option value=\"".$row['cat_id']."\">".$n.$row['cat_name']."</option>\r\n";
}
sort_s($row['cat_id']);
}
}
function sort_s($id){ $sql="select * from article_cat where parent_id=".$id;
$result =mysql_query($sql); while($row = mysql_fetch_array($result)){
$rid=explode(",",$row['depth']);
$i=count($rid);
$n = str_pad('',$i,'-',STR_PAD_RIGHT);
$n = str_replace("-"," ",$n); if($row['parent_id']==0){ echo "<option value=\"".$row['cat_id']."\" style='background:#ccc' >".$row['cat_name']."</option>\r\n";
}else{
echo "<option value=\"".$row['cat_id']."\">".$n.$row['cat_name']."</option>\r\n";
}
sort_s($row['cat_id']);
}
}
觉得你应该学下模板的用法
注意:此时的模板文件是在模板中嵌套子模板的