Home  >  Article  >  Backend Development  >  PHP无限级分类的展示有关问题。折腾一天了,搞不定呀

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

WBOY
WBOYOriginal
2016-06-13 12:12:39983browse

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

<br />//无限分类显示函数<br />function get_str($id = 0) { <br />    global $str; <br />    $sql = "select classid,classname,classstate,classtype,classurl,classpage,classorder,classtitle,classkeyword,classdescription,classpid from bz_class where classpid= $id";  <br />    $result = mysql_query($sql);//查询pid的子类的分类 <br />    if($result && mysql_affected_rows()){//如果有子类 <br />        while ($row = mysql_fetch_array($result)) { //循环记录集<br />		 	$str.= "<tr><td>" .$row['classid']. "</td><td>". $row['classname']. "<p>ID: 882233</p></td><td>". $row['classtype']."</td><td>". $row['classid']."</td><td>". $row['classid']."</td><td>". $row['classid']."</td></tr>" ; //字符串构建<br />            get_str($row['classid']); //调用get_str(),将记录集中的id参数传入函数中,继续查询下级 <br />        } <br />    } <br />    return $str; <br />} <br />



求高手赐教。

------解决思路----------------------

本帖最后由 fdipzone 于 2014-12-27 18:25:50 编辑 试试
<br />//无限分类显示函数<br />function get_str($id = 0, $depth=0) { <br />    global $str; <br />    $sql = "select classid,classname,classstate,classtype,classurl,classpage,classorder,classtitle,classkeyword,classdescription,classpid from bz_class where classpid= $id";  <br />    $result = mysql_query($sql);//查询pid的子类的分类 <br />    if($result && mysql_affected_rows()){//如果有子类 <br />        while ($row = mysql_fetch_array($result)) { //循环记录集<br />            $str.= "<tr><td>" .$row['classid']. "</td><td>".str_repeat ( "└" ,$depth). $row['classname']. "<p>ID: 882233</p></td><td>". $row['classtype']."</td><td>". $row['classid']."</td><td>". $row['classid']."</td><td>". $row['classid']."</td></tr>" ; //字符串构建<br />            get_str($row['classid'], $depth+1); //调用get_str(),将记录集中的id参数传入函数中,继续查询下级 <br />        } <br />    } <br />    return $str; <br />}<br />
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn