PHP無限級分類的展示問題。折騰一天了,搞不定呀

來源:互聯網
上載者:User
函數:
//無限分類顯示函數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; }




這個可以用,高人呀,我折騰了一天,非常感謝。
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.