本文实例讲述了smarty表格换行的实现方法。分享给大家供大家参考。具体分析如下:
在foreach中加入 key=count
复制代码 代码如下:
<table>
<{foreach item=item from=$items key=count}>
<{if $count is div by 2}><tr>
<{/if}>
<td><{$item.name}></td>
<td><{$item.summary}></td>
<td><{$item.date}></td>
<{if ($count+1) is div by 2}></tr><{/if}>
<{/foreach}></table>
<{foreach item=item from=$items key=count}>
<{if $count is div by 2}><tr>
<{/if}>
<td><{$item.name}></td>
<td><{$item.summary}></td>
<td><{$item.date}></td>
<{if ($count+1) is div by 2}></tr><{/if}>
<{/foreach}></table>
每行放置三个 <{$item.name}> 后换行 你喜欢换多少就改改参数就可以了!
复制代码 代码如下:
<table>
<tr>
<{foreach item=item from=$items key=count}>
<td><{$item.name}></td>
<{if ($count+1) is div by 3}></tr><tr><{/if}>
<{/foreach}>
</tr></table>
<tr>
<{foreach item=item from=$items key=count}>
<td><{$item.name}></td>
<{if ($count+1) is div by 3}></tr><tr><{/if}>
<{/foreach}>
</tr></table>
另一种利用 cycle 來做换行的例子,但只能作到每行两条数据就换行的效果 只能换两行
复制代码 代码如下:
<table>
<tr>
<{foreach item=item from=$items}>
<td><{$item.name}>
<{cycle values="</td>,</td></tr><tr>"}>
<{/foreach}>
</tr>
</table>
<tr>
<{foreach item=item from=$items}>
<td><{$item.name}>
<{cycle values="</td>,</td></tr><tr>"}>
<{/foreach}>
</tr>
</table>
希望本文所述对大家的PHP程序设计有所帮助。
最后
以上就是细心麦片最近收集整理的关于smarty表格换行实例的全部内容,更多相关smarty表格换行实例内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复