PHP SMARTY double Loop (recursive) output classification problem
Templates
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_r ow ()) { $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 ');
This can only output one-level classifications. I need to output level two in the first level category. Level Three: How do you write it?
Effects that were previously output with ASP
HTML Code
News Topics
- +--News
- +--theme of the Great Beauty
- +--Moon Rabbit Special Topic
Supply and demand information product display
- +--Mei da Cooker
- +--Monthly Chart Kitchen cabinet
- +--Integration Effect
The 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 (" cl Assname ")%><% end if%> <%call showparentclass (" + ","--", RS (" id "))%><%rs.movenextwendrs.clos Eset rs = nothing%><%sub Showparentclass (astr,tree,parentid) Dim Showparentclassrs,temprs Set SHOWPARENTCLASSR s = Conn.execute ("select * from jh_newsclass where parentid =" & ParentID) if Showparentclassrs.eof then E XIT 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 Wen D Response. Write ("
") End IfEnd Sub%>