我有一个动态填充的表格,我想将其中的列数限制为 3,以便下一行的下一个 td
星号。 (请参阅 http://kbay.in 并检查页面顶部的类别按钮。)
下面是我如何使用 Smarty PHP 导入数据:
<table cellpadding="0" cellspacing="4" width="100"; border-collapse="collapse";>
<tr>
{foreach from=$array_categories item=v name=cat}
<td valign="top" width="116px" align="left">
{capture name=some_content assign=categ_url}
{if $v.subcats>0}{$live_site}/{if $seo_settings.enable_mod_rewrite}{$v.id}-{$v.url_title}/1/listings.html{else}listings.php?category={$v.id}{/if}{/if}
{/capture}
<a href="{$categ_url}">{$v.name|escape:"html"}{if $appearance.categ_count_ads} ({$v.ads}) {/if}</a>
{/foreach}</td></tr> </table>
我怎样才能使每行只有 3 个表格单元格?
最佳答案
使用 iteration
foreach
循环的属性:
...
{foreach from=$array_categories item=v name=cat}
{if $smarty.foreach.cat.iteration % 3 == 0 && $smarty.foreach.cat.iteration > 0}
</tr>
<tr>
{/if}
<td valign="top" width="116px" align="left">
...
$smarty.foreach.cat.iteration
是Smarty2语法,如果你使用Smarty3你也可以使用$v@iteration
。
关于php - 如何将每个表格行的单元格数限制为 3?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7286160/