当前位置:Gxlcms > PHP教程 > PHPSMARTY双循环(递归)输出分类有关问题

PHPSMARTY双循环(递归)输出分类有关问题

时间:2021-07-01 10:21:17 帮助过:17人阅读

PHP SMARTY 双循环(递归)输出分类 问题
模版
PHP code
  1. <!--
  2. Code highlighting produced by Actipro CodeHighlighter (freeware)
  3. http://www.CodeHighlighter.com/
  4. -->{foreach from=$classlist item=newsclass}
  5. {$newsclass.classname}
  6. {/foreach}


程序
PHP code
  1. <!--
  2. Code highlighting produced by Actipro CodeHighlighter (freeware)
  3. http://www.CodeHighlighter.com/
  4. -->$sql = "select * from jh_newsclass where parentid = 0";
  5. $result = $mysqli->query($sql);
  6. while ($row = $result->fetch_row()) {
  7. $classlist[] = array(
  8. 'id'=>$row[0],
  9. 'classname'=>$row[2],
  10. 'parentid'=>$row[1],
  11. 'ispro'=>$row[3],
  12. );
  13. }
  14. $result->close();
  15. $mysqli->close();
  16. $smarty->assign('classlist',$classlist);
  17. $smarty->assign('webname',Webname);
  18. $smarty->display('admin/left.htm');



这样只能输出一级分类. 我需要在一级分类下再输出二级..三级..该怎么写呀?


以前用ASP输出的效果
HTML code
  1. <!--
  2. Code highlighting produced by Actipro CodeHighlighter (freeware)
  3. http://www.CodeHighlighter.com/
  4. --> 新闻专题
  5. <ul><li class="forumli">+--<img id="folder180" src="https://www.gxlcms.com/images/leaf.gif" width="18" height="18" align="absmiddle"><font color="">新闻动态</font></li><li class="forumli">+--<img id="folder180" src="https://www.gxlcms.com/images/leaf.gif" width="18" height="18" align="absmiddle"><font color="">美大专题</font></li><li class="forumli">+--<img id="folder180" src="https://www.gxlcms.com/images/leaf.gif" width="18" height="18" align="absmiddle"><font color="">月兔专题</font></li></ul>
  6. 供求信息
  7. 产品展示
  8. <ul><li class="forumli">+--<img id="folder180" src="https://www.gxlcms.com/images/leaf.gif" width="18" height="18" align="absmiddle"><font color="">美大灶具</font></li><li class="forumli">+--<img id="folder180" src="https://www.gxlcms.com/images/leaf.gif" width="18" height="18" align="absmiddle"><font color="">月图厨柜</font></li><li class="forumli">+--<img id="folder180" src="https://www.gxlcms.com/images/leaf.gif" width="18" height="18" align="absmiddle"><font color="">集成效果</font></li></ul>



原来的ASP代码
HTML code
  1. <!--
  2. Code highlighting produced by Actipro CodeHighlighter (freeware)
  3. http://www.CodeHighlighter.com/
  4. -->
  5. <%
  6. dim strs
  7. Set Rs = server.CreateObject(JH_RS)
  8. sql = "select * from jh_newsclass where parentid = 0"
  9. Rs.Open SQL,Conn,1,1
  10. while not rs.eof
  11. %>
  12. <%
  13. set strs = conn.execute("select * from jh_newsclass where parentid = " & rs("id"))
  14. if strs.eof and strs.bof then
  15. %>
  16. &newsclass=<%=rs("id")%><%if rs("ispro") then response.Write("&ispro=true")%>" target="main"><%=rs("classname")%>
  17. <%
  18. else
  19. %>
  20. <%=rs("classname")%>
  21. <%
  22. end if
  23. %>
  24. <%call showparentclass("+","--",rs("id"))%>
  25. <%
  26. rs.movenext
  27. wend
  28. rs.close
  29. set rs = nothing
  30. %>
  31. <%
  32. sub showparentclass(astr,tree,parentid)
  33. dim showparentclassrs,temprs
  34. set showparentclassrs = conn.execute("select * from Jh_newsclass where parentid = " & parentid)
  35. if showparentclassrs.eof then
  36. exit sub
  37. else
  38. response.Write("<ul>")
  39. while not showparentclassrs.eof
  40. response.Write"<li class="" forumli""="">"
  41. set temprs = conn.execute("select * from Jh_newsclass where parentid = " & showparentclassrs("id"))
  42. if temprs.eof and temprs.bof then
  43. response.Write"" & astr & tree & "<img id="" folder180""="" src="" https:="" www.gxlcms.com="" images="" leaf.gif""="" width="" 18""="" height="" align="" absmiddle""=""><font color="" ""="">" & showparentclassrs("classname")&"</font>"
  44. else
  45. response.Write astr & tree & "<img id="" folder180""="" src="" images="" folderclosed.gif""="" width="" 18""="" height="" align="" absmiddle""="">" & showparentclassrs("classname")
  46. end if
  47. set temprs = nothing
  48. response.Write"</li>"
  49. call showparentclass(astr,tree&"--",showparentclassrs("id"))
  50. showparentclassrs.movenext
  51. wend
  52. response.Write("</ul>")
  53. end if
  54. end sub
  55. %>

人气教程排行