簡體   English   中英

如何將每個表行的單元格數限制為3?

[英]How to limit the number of cells per table row to 3?

我有一個動態填充的表,在該表中,我想將列數限制為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個表格單元格?

使用foreach循環的iteration屬性:

...
{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

每次在循環中增加一個計數器,並在必要時在循環中進行檢查以開始新的一行。 就像是:

if ($counter % 3 == 0) {
    echo '</tr><tr>';
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM