PHP SMARTY Dual-loop (recursive) output classification related issues

Source: Internet
Author: User
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%>
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.