smarty表格換行實(shí)例
更新時(shí)間:2014年12月15日 15:02:11 投稿:shichen2014
這篇文章主要介紹了smarty表格換行的方法,可實(shí)現(xiàn)針對(duì)表格的靈活操作,需要的朋友可以參考下
本文實(shí)例講述了smarty表格換行的實(shí)現(xiàn)方法。分享給大家供大家參考。具體分析如下:
在foreach中加入 key=count
復(fù)制代碼 代碼如下:
<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>
每行放置三個(gè) <{$item.name}> 后換行 你喜歡換多少就改改參數(shù)就可以了!
復(fù)制代碼 代碼如下:
<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 來做換行的例子,但只能作到每行兩條數(shù)據(jù)就換行的效果 只能換兩行
復(fù)制代碼 代碼如下:
<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>
希望本文所述對(duì)大家的PHP程序設(shè)計(jì)有所幫助。
相關(guān)文章
PHP實(shí)現(xiàn)將textarea的值根據(jù)回車換行拆分至數(shù)組
這篇文章主要介紹了PHP實(shí)現(xiàn)將textarea的值根據(jù)回車換行拆分至數(shù)組,涉及表單元素及explode拆分字符串的相關(guān)技巧,需要的朋友可以參考下2015-06-06使用php來實(shí)現(xiàn)網(wǎng)絡(luò)服務(wù)
在調(diào)用網(wǎng)絡(luò)服務(wù)的過程中,需要兩個(gè)消息,發(fā)送的消息和接受的消息,又來有往方能來往不是。2009-09-09