(Fwd) Re: [SMARTY] adding vars to array
| From: | Ferdinand Beyer | Date: | Fri, 12 Jul 2002 14:10:30 +0000 |
| Subject: | (Fwd) Re: [SMARTY] adding vars to array | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-5267@lists.php.net to get a copy of this message | ||
On 12 Jul 2002 at 14:03, Peter Billen wrote:
> Is it possible to add vars to an array with using Smarty, so I can do
> something like:
>
> $t = new Smarty();
>
> $db->query(". my sql query .");
>
> while ($row = $db->fetch_array())
> {
> $t->addvar("date",$row['field1']);
> .
> }
>
> if ($db->num_rows())
> $t->display(.)
Use Smarty's append() method for that:
while ($row = $db->fetch_array()) {
$t->append("date", $row['field 1']);
}
This produces the template variable $date - an array - and pushes
values to it:
$t->append('arr', 'Zero');
$t->append('arr', 'One');
$t->append('arr', 'Two');
========================================
{foreach loop=$arr key="key" item="value"}
{$key} - {$value}<br />
{/foreach}
Outputs:
0 - Zero
1 - One
2 - Two
(not tested, should work)
Please look up the append() method in the docs for further details.
--
Ferdinand Beyer
<fbeyer@clickhand.de>--
Ferdinand Beyer
<fbeyer@clickhand.de>