[SMARTY] Re: How to iterate in a table ...

Pedro <[email protected]>
Newsgroups gmane.comp.php.smarty.general
Message-ID <[email protected]>
check out the first, last and index properties, you need something along 
the lines of..(psuedo code)

{assign var=cols value=3}
<table>
{foreach from=$ac item=element name=f}
{if $smarty.foreach.f.first}
<tr>
{/if}

{if $smarty.foreach.f.index % $cols ==0}
</tr><tr>
{/if}
<td>{$element}</td>
{/foreach}
</table>

regards

Pete

Reynier Perez Mira wrote:
> Hi to every:
> I know how to iterate with elements came from array. For example this:
> PHP Code:
> ----
> $query = $db->Execute("SELECT *  FROM tabla"); // this return at least 10 elements
> $ac = array();
> while ( $record = $query->fetchRow() ) {
>  $ac[] = $record;
> }
> $tpl->assign('ac', $ac);
> 
> TPL Code:
> ---
> <table widht="100%" cellpadding="0" cellspacing="1" border="0">
> {foreach from=$ac item=element name=it}
>  <tr>
>    <td>{$element.ID}</td>
>    <td>{$element.Name}</td> </tr>
> {/foreach}
> </table>
> 
> This code repeat ten times a row with two columns. Now I need to build a table with two columns but in another way. Mean this:
> 
> <table width="100%" border="0" cellspacing="0" cellpadding="0">
>   <tr>
>     <td>Element1</td>
>     <td>Element2</td>
>     <td>Element3</td>
>   </tr>
>   <tr>
>     <td>Element4</td>
>     <td>Element5</td>
>     <td>Element6</td>
>   </tr>
>   <tr>
>     <td>Element7</td>
>     <td>Element8</td>
>     <td>Element9</td>
>   </tr>
> </table>
> 
> Understand ?
> Best,

-- 
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.