<tr>
{foreach key=key item=item from=$array1 name=name}
<td align="center" valign="middle">
<img src="路径<!--这里显示路径 变量:picpath-->" width="182" height="66">标题<!--这里显示标题 变量:pictitle-->
</td>    
{if $smarty.foreach.name.iteration%3==0}</tr><tr>{/if}
{/foreach>
</tr>没测试,随手写的,借鉴下思想就行了

解决方案 »

  1.   

    smarty test.htm页面 
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>测试</title>
    </head>
    <body>
    <table width="100%" height="240" border="0" cellspacing="0" cellpadding="0">  {section name=sec loop=$array1}
      {if $smarty.section.sec.index%3 ==0 }
      <tr>
      {/if}  
       <td align="center" valign="middle">
        <img src="{$array1[sec].picpath}" width="182" height="66">{$array1[sec].pictitle}
       </td>
      {if $smarty.section.sec.index%3 ==0 }
      </tr>
      {/if} 
      {/section}
    </table>
    </body>
    </html>
      

  2.   

    不行啊!<img src="路径<!--这里显示路径 变量:picpath-->" width="182" height="66">这里应该怎么显示
      

  3.   

    2楼的逻辑有问题,应该这样:
      {if $smarty.section.sec.index%3 ==0 && $smarty.section.sec.index  }
      </tr>
      {/if}
      {/section}
      {if $smarty.section.sec.index%3}
      </tr>
      {/if}
    否则,当array1的长度不是3的整数时会出问题。当然,像这样的显示方式最好不要用table,用li或div标签浮动定位,宽度30%,这样就不需要这么啰嗦的显示逻辑了
      

  4.   


    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>测试</title>
    </head>
    <body>
    <table width="100%" height="240" border="0" cellspacing="0" cellpadding="0">
      {section name=sec loop=$array1}
      {if $smarty.section.sec.index%3 ==0 && $smarty.section.sec.index }  <tr>
      {/if}  
       <td align="center" valign="middle">
        <img src="{$array1[sec].picpath}" width="182" height="66">{$array1[sec].pictitle}
       </td>
      {if $smarty.section.sec.index%3 ==0 }
      </tr>
      {/if} 
      {/section}
    </table>
    </body>
    </html>
    但是出来了的格式不对啊!格式如下
     
         图片1
        图片2  图片3
        图片4  怎么成这样了!
      

  5.   


    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>测试</title>
    </head>
    <body>
    <table width="100%" height="240" border="0" cellspacing="0" cellpadding="0">
      {section name=sec loop=$array1}
      {if $smarty.section.sec.index%3 ==0 && $smarty.section.sec.index }  <tr>
      {/if}  
       <td align="center" valign="middle">
        <img src="{$array1[sec].picpath}" width="182" height="66">{$array1[sec].pictitle}
       </td>
      {if $smarty.section.sec.index%3 ==0 && $smarty.section.sec.index }
      </tr>
      {/if} 
      {/section}
    </table>
    </body>
    </html>这样就好了!
      

  6.   

    我在4楼补充了一下:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>测试</title>
    </head>
    <body>
    <table width="100%" height="240" border="0" cellspacing="0" cellpadding="0">
    {section name=sec loop=$array1}
      {if $smarty.section.sec.index%3 ==0 }<tr>{/if}  
       <td align="center" valign="middle">
        <img src="{$array1[sec].picpath}" width="182" height="66">{$array1[sec].pictitle}
       </td>
     {if $smarty.section.sec.index%3 ==0 && $smarty.section.sec.index or $smarty.section.sec.last}
      }
      </tr>
      {/if}
    {/section}</table>
    </body>
    </html>
    本来挺简单的一用表格就麻烦了,你试一下下面的:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>测试</title>
    </head>
    <body>
    <div style="width:100%;height:240px;">
    {section name=sec loop=$array1}
        <div style="float:left; text-align:center; width:30%;margin-top:2px;height:100px;"> 
    <img src="{$array1[sec].picpath}" width="182" height="66">{$array1[sec].pictitle}
    </div>
    {/section}
    </div>
    </body>
    </html>
      

  7.   


    <table width="100%" height="240" border="0" cellspacing="0" cellpadding="0">
    <!--这里好像少了一个<tr>-->
     <td align="center" valign="middle">
      <img src="/admin/flash/upload/pic/1229307819.jpg" width="182" height="66">测试2
     </td>
     <td align="center" valign="middle">
      <img src="/admin/flash/upload/pic/1229307890.jpg" width="182" height="66">测试3
     </td>
     <td align="center" valign="middle">
      <img src="/admin/flash/upload/pic/1229307917.jpg" width="182" height="66">测试4
     </td> <tr>
       <td align="center" valign="middle">
         <img src="/admin/flash/upload/pic/1229307961.jpg" width="182" height="66">测试5
       </td>
     </tr>
    </table>
    那里少了一对<tr></tr>没关系吧!
      

  8.   

    但是好像位置有点偏一个一个往下错了半格似的!
    ===================
    没有呀,在ie6和firefox里都正常
      

  9.   


    <table width="100%" height="240" border="0" cellspacing="0" cellpadding="0">
    <!--这里好像少了一个<tr>-->
     <td align="center" valign="middle">
      <img src="/admin/flash/upload/pic/1229307819.jpg" width="182" height="66">测试2
     </td>
     <td align="center" valign="middle">
      <img src="/admin/flash/upload/pic/1229307890.jpg" width="182" height="66">测试3
     </td>
     <td align="center" valign="middle">
      <img src="/admin/flash/upload/pic/1229307917.jpg" width="182" height="66">测试4
     </td> <tr>
       <td align="center" valign="middle">
         <img src="/admin/flash/upload/pic/1229307961.jpg" width="182" height="66">测试5                    
       </td>
     </tr>
    </table>在问一遍!那里少了一对 <tr> </tr>没关系吧!
      

  10.   

    用div比较简单,用表格太麻烦了
      

  11.   

    不对啊!各位师哥们!我添加了六张图片后得到结果是下面这个结果排序都乱了!<table width="100%" height="240" border="0" cellspacing="0" cellpadding="0">
    <td align="center" valign="middle">
    <img src="/admin/flash/upload/image/1229307782.jpg" width="182" height="66">ffffffffffff  
    </td>
    <td align="center" valign="middle">
    <img src="/admin/flash/upload/image/1229307782.jpg" width="182" height="66">ggggggggg
    </td>
    <td align="center" valign="middle">
    <img src="/admin/flash/upload/image/1229307782.jpg" width="182" height="66">aaaaaaaa
    </td>
    <tr>
    <td align="center" valign="middle">
    <img src="/admin/flash/upload/image/1229307782.jpg" width="182" height="66">
    bbbbbbbbbbbb  
    </td>
    </tr>
    <td align="center" valign="middle">
    <img src="/admin/flash/upload/image/1229307782.jpg" width="182" height="66">
    ccccccc  
    </td>
    <td align="center" valign="middle">
    <img src="/admin/flash/upload/image/1229307782.jpg" width="182" height="66">
    ddddddddddddd
    </td>
    <tr>
    <td align="center" valign="middle">
    <img src="/admin/flash/upload/image/1229307782.jpg" width="182" height="66">
    eeeeeeeeeeee
    </td>
    </tr>
    </table>
    帮忙给看看啊!
      

  12.   

    不行!还是和我14楼贴出来的一样!但是用你的div方式倒是可以!为什么HTML那种格式不行那!
      

  13.   

    感觉很多人都把问题搞的好复杂哦<{section name='' loop='' start=0 step=3}>
    横向图片1
    <{/section}>
    <{section name='' loop='' start=1 step=3}>
    横向图片2
    <{/section}>
    <{section name='' loop='' start=2 step=3}>
    横向图片3
    <{/section}>这个适合于表格
      

  14.   

    终于搞定了,没想到还这么麻烦
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>测试</title>
    </head>
    <body>
    <table width="100%" height="240" border="0" cellspacing="0" cellpadding="0">
    {section name=sec loop=$array1 }
      {if $smarty.section.sec.index %3 ==0 }<tr>{/if}  
       <td align="center" valign="middle">
        <img src="{$array1[sec].picpath}" width="182" height="66">{$array1[sec].pictitle}
       </td>
     {if $smarty.section.sec.index%3==2  || $smarty.section.sec.last }
      </tr>
      {/if}
    {/section}
    </table>
    </body>
    </html>