Re: Pears DB Abstraction and Smarty
| From: | Brian E . Lozier | Date: | Wed, 20 Feb 2002 18:22:41 +0000 |
| Subject: | Re: Pears DB Abstraction and Smarty | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-2783@lists.php.net to get a copy of this message | ||
It doesn't look like you're assigning the results of the data anywhere... you need to have
a line that has
your smarty object and the assign method:
$smarty->assign('data', $data);
Brian
------------------------------------
"How should I know if it works? That's what beta testers are for. I only coded it." -
Linus Torvalds
----- Original Message -----
From: chiefmonkey <chiefmonkey@wisemonkeydesign.co.uk>
To: smarty@lists.ispi.net
Date: 2/20/02 3:11:40 AM
>
>I am getting a bit confused now ( easily done)
> I have a php file which connects to the database using the Pear DB
>abstraction layer called dbcon.php
> ---------------------------------
>
><?php
>
> //Include the extraction layer
>
> include("DB.php");
>
> //connect to the database
> $dbh=DB::connect("mysql://user:password@localhost/database);
>
> //execute query
> $query="SELECT * FROM latestnews";
>
>
> $result= $dbh->query($query);
>
> while ($row = $result->fetchrow(DB_FETCHMODE_ASSOC)) {
>$data[] = $row;
>}
> $dbh->disconnect();
>
> ?>
> which returns
>
> Array ( [0] => Array ( [name] => test1 [story] => test11 ) [1] => Array (
>[name] => test2 [story] => test22 ) )
>
> Then in a template I use
> {include_php file="dbcon.php"}
>
>{foreach item=section from=$data}
> {$section.name}<br> {$section.story}<br>
>{/foreach}
>
>
> Won't this work
>
> George
>
>
>
>At 11:39 20/02/2002 +0100, Luc Saint-Elie wrote:
>>Hello,
>>
>>Have a look also at :
>>
>>http://www.phpinsider.com/php/code/Smarty/contribs/examples/mysql/
>>
>>
>>Luc
>>
>>At 10:36 20/02/02 +0000, Peter Bowyer wrote:
>>>At 09:44 AM 2/20/02 +0000, chiefmonkey wrote:
>>>> $row=$result->fetchrow(DB_FETCHMODE_ASSOC))
>>>
>>>You need to use
>>>while ($row = $result->...) {
>>>$data[] = $row;
>>>}
>>>$smarty->assign('row', $data);
>>>
>>>and you should have more luck. Read the PEAR manual for more examples.
>>
>>
>>---
>>You are currently subscribed to smarty as: chiefmonkey@wisemonkeydesign.co.uk
>>To unsubscribe send a blank email to $subst('Email.Unsub')
>>Visit Smarty's homepage at
>>http://www.phpinsider.com/php/code/Smarty/
>
>
>---
>You are currently subscribed to smarty as: brian@massassi.net
>To unsubscribe send a blank email to $subst('Email.Unsub')
>Visit Smarty's homepage at
>http://www.phpinsider.com/php/code/Smarty/