|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
iDİlE Smarty Rookie
Joined: 18 Aug 2004 Posts: 9
|
Posted: Thu Aug 26, 2004 2:29 am Post subject: Dynamic table columns -->yet another way<-- |
|
|
Well I ran into a prob when using {section} and adding html inside it with text and images. Thanks to a good friend helping there is yet another way.
First MYSql array with DB:
Code: |
#assign number of rows
$cols_per_row = 3
$results = "SELECT * FROM your_table WHERE your where
$res = $db->query($results);
while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
$array[] = $row;
}
$smarty->assign('cols_per_row', $cols_per_row);
$smarty->assign("array", $array);
|
Now your corresponding .tpl:
Code: |
<table>
{section name=sec1 loop=$array}
{if %sec1.index% % $cols_per_row == 0}
<tr>
{/if}
<td>phone: {$array[sec1].phone}<br /><img src="path{$array[sec1].i}.gif" /></td>
{if ((%sec1.index% + 1) % $cols_per_row) == 0 || %sec1.last%}
</tr>
{/if}
{/section}
</table>
|
Hope this helps someone!
iDİle |
|
Back to top |
|
Ceph Smarty Rookie
Joined: 25 Nov 2003 Posts: 24
|
Posted: Sun Sep 05, 2004 1:44 am Post subject: |
|
|
And something similiar, minus the section structure (very simple):
Code: |
{assign var="i" value=0}
{foreach from=$data item=item}
{if !$i}<tr>{/if}
<td>{$item->firstname} {$item->lastname}</td>
{assign var="i" value=$i+1}
{if $i == 4}</tr>{assign var="i" value=0}{/if}
{/foreach}
{if !$i}</tr>{/if}
| [/code] |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|