PHP无限级分类的展示问题。折腾一天了,搞不定呀

原创
2016-06-23 13:42:35 815浏览

函数:

//无限分类显示函数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

". $row['classtype']."". $row['classid']."". $row['classid']."". $row['classid']."" ; //字符串构建 get_str($row['classid']); //调用get_str(),将记录集中的id参数传入函数中,继续查询下级 } } return $str; }



求高手赐教。


回复讨论(解决方案)

试试

//无限分类显示函数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; }

get_str($row['classid']); //调用get_str(),将记录集中的id参数传入函数中,继续查询下级

这句返回的$str没有使用。



麻烦您,能写个代码我学习一下吗?折腾一天了。

参考: http://www.jb51.net/article/36220.htm

试试

//无限分类显示函数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; }



这个可以用,高人呀,我折腾了一天,非常感谢。
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。