PHPSMARTY dual-loop (recursive) output classification problems

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

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.