我想在ecshop中添加一个统计排行,对资金的前十名进行排序,把数据找出来了,但是在dwt页面,(使用的是smarty框架)使用foreach将统计显示出来,却不会用了,怎么处理呢,高手帮帮忙?
   这是php的处理 $sqla= "SELECT * FROM " . $ecs->table('users') . " order by user_money desc limit 10 ";
$ra = mysql_fetch_array(mysql_query($sqla));
$smarty->assign('ress', $ra);
  这是dwt页面的显示调用
                <!-- {foreach from=$ress key=level item=ee name=ress} -->
                        <tr align="center">
                       <td bgcolor="#ffffff">{$val.num}</td>
                       <td bgcolor="#ffffff">{$val.user_money}</td>
                        <td bgcolor="#ffffff">{$val.user_money}</td>
                        <td bgcolor="#ffffff">{$val.user_money}</td>
                        </tr>
                   <!-- {/foreach} -->
    就是上面forerecah的使用 <!-- {foreach from=$ress key=level item=ee name=ress} -->这一句不知道怎么写?

解决方案 »

  1.   

    dwt模板~没有玩过~晕~
    如果是学Smarty你还是看一下这篇文章:http://www.php002.cn/chujijiaocheng/cainiaoxuePHPzhiSmartyrumen_8786.html
      

  2.   

    正规Smarty模板应该是这样:
    test2.php:
      
      <?php
      require "main.php";
      $array1 = array(1 => "苹果", 2 => "菠萝", 3 => "香蕉", 4 => "芭乐");
      $tpl->assign("array1", $array1);
      $array2 = array(
      array("index1" => "data1-1", "index2" => "data1-2", "index3" => "data1-3"),
      array("index1" => "data2-1", "index2" => "data2-2", "index3" => "data2-3"),
      array("index1" => "data3-1", "index2" => "data3-2", "index3" => "data3-3"),
      array("index1" => "data4-1", "index2" => "data4-2", "index3" => "data4-3"),
      array("index1" => "data5-1", "index2" => "data5-2", "index3" => "data5-3"));
      $tpl->assign("array2", $array2);
      $tpl->display("test2.htm");
      ?>
      
      而模版的写法如下:
      
      templates/test2.htm:
      
      <html>
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=big5">
      <title>测试重复区块</title>
      </head>
      <body>
      <pre>
      利用 foreach 来呈现 array1
      <{foreach item=item1 from=$array1}>
      <{$item1}>
      <{/foreach}>
      利用 section 来呈现 array1
      <{section name=sec1 loop=$array1}>
      <{$array1[sec1]}>
      <{/section}>
      利用 foreach 来呈现 array2
      <{foreach item=index2 from=$array2}>
      <{foreach key=key2 item=item2 from=$index2}>
      <{$key2}>: <{$item2}>
      <{/foreach}>
      <{/foreach}>
      利用 section 来呈现 array1
      <{section name=sec2 loop=$array2}>
      index1: <{$array2[sec2].index1}>
      index2: <{$array2[sec2].index2}>
      index3: <{$array2[sec2].index3}>
      <{/section}>
      </pre>
      </body>
      </html>
      

  3.   

    参考资料Example Database example with {foreachelse}A database (eg PEAR or ADODB) example of a search script, the query results assigned to Smarty<?php
      $search_condition = "where name like '$foo%' ";
      $sql = 'select contact_id, name, nick from contacts '.$search_condition.' order by name';
      $smarty->assign('results', $db->getAssoc($sql) );
    ?>  The template which display "None found" if no results with {foreachelse}.{foreach key=cid item=con from=$results}
        <a href="contact.php?contact_id={$cid}">{$con.name} - {$con.nick}</a><br />
    {foreachelse}
        No items were found in the search
    {/foreach}
     
      

  4.   

     <!-- {foreach from=$ress key=level item=ee } --> 
                            <tr align="center"> 
                          <td bgcolor="#ffffff">{$ee .num} </td> 
                          <td bgcolor="#ffffff">{$ee .user_money} </td> 
                            <td bgcolor="#ffffff">{$ee .user_money} </td> 
                            <td bgcolor="#ffffff">{$ee .user_money} </td> 
                            </tr> 
                      <!-- {/foreach} --> 
    这样就可以了