<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>没测试,随手写的,借鉴下思想就行了
<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>
{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%,这样就不需要这么啰嗦的显示逻辑了
<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 怎么成这样了!
<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>这样就好了!
<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>
<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>没关系吧!
===================
没有呀,在ie6和firefox里都正常
<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>没关系吧!
<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>
帮忙给看看啊!
横向图片1
<{/section}>
<{section name='' loop='' start=1 step=3}>
横向图片2
<{/section}>
<{section name='' loop='' start=2 step=3}>
横向图片3
<{/section}>这个适合于表格
<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>