PHP无限级分类的展示问题。折腾一天了,搞不定呀
函数:
//无限分类显示函数
function get_str($id = 0) {
global $str;
$sql = "select classid,classname,classstate,classtype,classurl,classpage,classorder,classtitle,classkeyword,classdescription,classpid from bz_class where classpid= $id";
$result = mysql_query($sql);//查询pid的子类的分类
if($result && mysql_affected_rows()){//如果有子类
while ($row = mysql_fetch_array($result)) { //循环记录集
$str.= "| " .$row['classid']. " | ". $row['classname']. " id: 882233
ChatX翻译
最实用、可靠的社交类实时翻译工具。 支持全球主流的20+款社交软件的聊天应用,全球200+语言随意切换。 让您彻底告别复制粘贴的翻译模式,与世界各地高效连接!
下载
| ". $row['classtype']." | ". $row['classid']." | ". $row['classid']." | ". $row['classid']." |
" ; //字符串构建
get_str($row['classid']); //调用get_str(),将记录集中的id参数传入函数中,继续查询下级
}
}
return $str;
}

求高手赐教。
------解决思路----------------------
本帖最后由 fdipzone 于 2014-12-27 18:25:50 编辑 试试
//无限分类显示函数
function get_str($id = 0, $depth=0) {
global $str;
$sql = "select classid,classname,classstate,classtype,classurl,classpage,classorder,classtitle,classkeyword,classdescription,classpid from bz_class where classpid= $id";
$result = mysql_query($sql);//查询pid的子类的分类
if($result && mysql_affected_rows()){//如果有子类
while ($row = mysql_fetch_array($result)) { //循环记录集
$str.= "| " .$row['classid']. " | ".str_repeat ( "└" ,$depth). $row['classname']. " id: 882233 | ". $row['classtype']." | ". $row['classid']." | ". $row['classid']." | ". $row['classid']." |
" ; //字符串构建
get_str($row['classid'], $depth+1); //调用get_str(),将记录集中的id参数传入函数中,继续查询下级
}
}
return $str;
}