PHPSMARTY dual-loop (recursive) output classification question Template PHPcode {foreachfrom = $ classlistitem = newsclass} & lt; DIVclass = & quot; bg03 & quot; & gt; & lt; ahref = & quot; news. php? Classid = {$ newsclas php smarty dual-loop (recursive) output classification problem
Template
PHP code
{foreach from=$classlist item=newsclass} {$newsclass.classname}{/foreach}
Program
PHP code
$sql = "select * from jh_newsclass where parentid = 0";$result = $mysqli->query($sql);while ($row = $result->fetch_row()) { $classlist[] = array( 'id'=>$row[0], 'classname'=>$row[2], 'parentid'=>$row[1], 'ispro'=>$row[3], );}$result->close();$mysqli->close();$smarty->assign('classlist',$classlist);$smarty->assign('webname',Webname);$smarty->display('admin/left.htm');
In this way, only the level-1 category can be output. I need to output level-2 under the level-1 category... how should I write?
Effects output by ASP in the past
HTML code
News Topics
- + -- News
- + -- Major topics
- + -- Moon rabbit topic
Supply and demand information product display
- + -- U.S. cooker
- + -- Monthly graph Kitchen Cabinet
- + -- Integration effect
Original ASP code
HTML code
<%dim strsSet Rs = server.CreateObject(JH_RS)sql = "select * from jh_newsclass where parentid = 0"Rs.Open SQL,Conn,1,1while not rs.eof%><% set strs = conn.execute("select * from jh_newsclass where parentid = " & rs("id")) if strs.eof and strs.bof then%> &newsclass=<%=rs("id")%><%if rs("ispro") then response.Write("&ispro=true")%>" target="main"><%=rs("classname")%><% else%> <%=rs("classname")%><% end if%> <%call showparentclass("+","--",rs("id"))%><%rs.movenextwendrs.closeset rs = nothing%><%sub showparentclass(astr,tree,parentid) dim showparentclassrs,temprs set showparentclassrs = conn.execute("select * from Jh_newsclass where parentid = " & parentid) if showparentclassrs.eof then exit sub else response.Write("
") while not showparentclassrs.eof response.Write"
- " set temprs = conn.execute("select * from Jh_newsclass where parentid = " & showparentclassrs("id")) if temprs.eof and temprs.bof then response.Write"" & astr & tree & "" & showparentclassrs("classname")&"" else response.Write astr & tree & "" & showparentclassrs("classname") end if set temprs = nothing response.Write"
" call showparentclass(astr,tree&"--",showparentclassrs("id")) showparentclassrs.movenext wend response.Write("
") end ifend sub%>