Solution for PHP Smarty three columns

Example 1

Create a three-column table. (Display x items in one colum. For example, list 50 US states in three columns, that is, 17, 17 and 16 in each column.)

<table border=’0′ cellpadding=’0′ cellspacing=’0′>
<td width=’33%’>
<{foreach name=states from=$data.states key=key item=state}>
<{capture name=’column’}><{math equation=”x % 17″ x=$smarty.foreach.states.index}><{/capture}>
<{if (($smarty.capture.column == “0″ ) && (($smarty.foreach.states.index != “0″ )))}>
</td><td width=’32%’ align=’left’>
<a href=”<{$rootDir}>state.php?pid=<{$}>”><{$}></a><br />

Example 2

Create a three-column table. (Display each item in a cell and there are 3x times items.)

<table border=”0″ cellpadding=”0″ cellspacing=”0″>
{foreach name=products from=$products item=product key=key}
{capture name=”column”}{math equation=”x % 3″ x=$key}{/capture}
{if ($smarty.capture.column == “0″)}
<td width=”33%” align=”left”>

No Comments

Leave a comment