{section name=aa loop=$array start=1 max=1} 
{$array[aa].id}
{$array[aa].name}
{/section} 

解决方案 »

  1.   

    你的是二维数组。 
    实际上这样表示数组就可以了。
    $array = array(1=>'name1',2=>'name2',3=>'name3');
    用  foreach
    {foreach name=p item=item key=key from=$array}
    {if $smarty.p.iteration/2==0}
         id:$key
         name:$item
    {/if}
    {/foreach}
      

  2.   

    {foreach name=p item=item key=key from=$array} 
    {if $smarty.p.iteration/2==0} 
        id:{$key} 
        name:{$item} 
    {/if} 
    {/foreach}
      

  3.   

    贴出代码大家可能更明白我的意思{foreach item=category from=$categories}
    <tr>
      <td bgcolor="#COCOCO" colspan="2"><strong>{$category.categoryj} </strong></td>
    </tr>
    <tr>
      <td colspan="2">
        <table width="100%" border="1" cellspacing="0" cellpading="5">
        {section name=product loop=$products}
        {if $products[product].categoryid eq $category.categoryid}
        <tr height="70">
          <td rowspan="2" width="15%"><a href="product.html">Thumbnail1</a></td>
          <td colspan="2" width="35%">
    {$products[$smarty.section.product.index].productname}<br>
    {$products[product].description|nl2br}
          </td>
          {if $products[$smarty.section.product.index_next].categoryid eq $category.categoryid}
    <td rowspan="2"><a href="product.html">Thumbnail2</a></td>
    <td colspan="2">
              {$products[$smarty.section.product.index_next].productname}<br>
      {$products[$smarty.section.product.index_next].description|nl2br}
    </td>
          {else}
            <td rowspan="2">&nbsp;</td>
    <td colspan="2">&nbsp;</td>
          {/if}
        </tr>
        <tr>
          <td align="center">Price: {$products[product].price}</td>
          <td align="center" nowrap="nowrap"><a href="product.html">Buy</a></td>
          {if $products[$smarty.section.product.index_next].categoryid eq $category.categoryid}
          <td><div align="center">Price: 4,000 </div></td>
          <td><div align="center"><a href="product.html">Buy</a></div></td>
          {else}
          <td><div align="center">&nbsp;</div></td>
          <td><div align="center">&nbsp;</div></td>
          {/if}
        </tr>
        {/if}
        {/section}
        </table>
      </td>
    </tr>
    {/foreach}实际上我是想根据不同的分类,显示产品,每行两个。上面代码还有问题,这个$smarty.section.product.index_next用的不对
      

  4.   

    {foreach item=category from=$categories} 
    <tr> 
      <td bgcolor="#COCOCO" colspan="2"> <strong>{$category.categoryj} </strong> </td> 
    </tr> 
    <tr> 
      <td colspan="2"> 
        <table width="100%" border="1" cellspacing="0" cellpading="5"> 
        {section name=product loop=$products} 
        {if $products[product].categoryid eq $category.categoryid} 
        <tr height="70"> 
          <td rowspan="2" width="15%"> <a href="product.html">Thumbnail1 </a> </td> 
          <td colspan="2" width="35%"> 
    {$products[$smarty.section.product.index].productname} <br> 
    {$products[product].description|nl2br} 
          </td> 
          {if $products[$smarty.section.product.index_next].categoryid eq $category.categoryid} 
    <td rowspan="2"> <a href="product.html">Thumbnail2 </a> </td> 
    <td colspan="2"> 
              {$products[$smarty.section.product.index_next].productname} <br> 
      {$products[$smarty.section.product.index_next].description|nl2br} 
    </td> 
          {else} 
            <td rowspan="2">&nbsp; </td> 
    <td colspan="2">&nbsp; </td> 
          {/if} 
        </tr> 
        <tr> 
          <td align="center">Price: {$products[product].price} </td> 
          <td align="center" nowrap="nowrap"> <a href="product.html">Buy </a> </td> 
          {if $products[$smarty.section.product.index_next].categoryid eq $category.categoryid} 
          <td> <div align="center">Price: 4,000 </div> </td> 
          <td> <div align="center"> <a href="product.html">Buy </a> </div> </td> 
          {else} 
          <td> <div align="center">&nbsp; </div> </td> 
          <td> <div align="center">&nbsp; </div> </td> 
          {/if} 
        </tr> 
        {/if} 
        {/section} 
        </table> 
      </td> 
    </tr> 
    {/foreach} 
      

  5.   

    变换了一种处理方式,将category和products存放到同一个数组中,通过section嵌套基本上解决问题。。谢谢大家的帮助
      

  6.   

    大致看了你的问题,
    index_next虽然会输出下一条数据,但并不能影响循环,所以你这种思路可能不行.