RE: [SMARTY] (Fwd) Re: [SMARTY] adding vars to array
| From: | Peter Billen | Date: | Fri, 12 Jul 2002 14:16:10 +0000 |
| Subject: | RE: [SMARTY] (Fwd) Re: [SMARTY] adding vars to array | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-5268@lists.php.net to get a copy of this message | ||
Thanks, i have tried it and it works, BUT:
Since I'm coding with error_reporting('E_ALL'); it gives an error (a
notice actually) when I use this method. It says: Undefined index: topic
in C:\...\Smarty.class.php on line 248.
I think this has something to do when I call this function for the first
time, so the array doesn't exist yet? I think that because this notice
is only given once.
My code:
---
$t = new Smarty();
$db->query(...);
while ($row = $db->fetch_array())
{
$t->append("topic",$row['...']);
}
if ($db->num_rows())
$t->display("...");
---
Peter
-----Original Message-----
From: Ferdinand Beyer [mailto:fbeyer@clickhand.de]
Sent: vrijdag 12 juli 2002 16:11
To: smarty-general@lists.php.net
Subject: [SMARTY] (Fwd) Re: [SMARTY] adding vars to array
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>
--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php