use foreach or section twice

解决方案 »

  1.   

    <!--{section name=loop loop=$yourArray}--><!--$yourArray//需是二维的-->
    $yourArray[loop].SubjectType;
    $yourArray[loop].Result;
    $yourArray[loop].Reason;
    <!--{/section}-->
      

  2.   

    试了,为什么每行只是相同的一位数字?-------test.php
    ...
    $rs=mysql_query($sql);
    $tpl->assign("yourArray",mysql_fetch_array($result));
    $tpl->display('test.tpl');-------test.tpl
    <!--{section name=loop loop=$yourArray}--><!--$yourArray//需是二维的-->
    $yourArray[loop].SubjectType;
    $yourArray[loop].Result;
    $yourArray[loop].Reason;
    <!--{/section}-->
      

  3.   

    1.php:<?php
    require "SmartyConfig.php";
    $arr = array(55 => array('ID' => array('SubjectType' => 'Answer',
                                           'QID'=> '19'
                                          )
                            ),
                 54 => array('ID' => array('SubjectType' => 'Question',
                                           'Result' => ''
                                          )
                            )
                );
    $smarty->assign("arr",$arr);
    $smarty->display("1.htm");
    ?>1.htm:<{foreach from=$arr key=K item=A}>
      <{$K}>:<br>
      <{foreach from=$A key=k item=a}>
        <{$k}>:<br>
        <{foreach from=$a item=value}>
          <{$value}> | 
        <{/foreach}>
      <{/foreach}>
      <hr>
    <{/foreach}>测试结果:55:
    ID:
    Answer | 19 | 
    --------------------------------------------------------------------------------
    54:
    ID:
    Question | |
      

  4.   

    我试的是数据库中取出的数组,结果取不出来
    -------test.php
    ...
    $rs=mysql_query($sql);
    $tpl->assign("yourArray",mysql_fetch_array($result));
    $tpl->display('test.tpl');-------test.tpl
    <!--{section name=loop loop=$yourArray}--><!--$yourArray//需是二维的-->
    $yourArray[loop].SubjectType;
    $yourArray[loop].Result;
    $yourArray[loop].Reason;
    <!--{/section}-->