Re: [SMARTY] PEAR::DB and Smarty

From: Date: Sat, 03 Aug 2002 07:57:45 +0000
Subject: Re: [SMARTY] PEAR::DB and Smarty
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-5569@lists.php.net to get a copy of this message
smarty-general, > <code> > while ($newsRow = $newsResult->fetchRow(DB_FETCHMODE_ASSOC)) { > $_SMARTY->assign("NEWSID", $newsRow['newsId']); > $_SMARTY->assign("NEWSTOPIC", $newsRow['newsTopic']); > $_SMARTY->assign("NEWSDATE", $newsRow['newsTopic']); > $_SMARTY->assign("NEWSSYNOPSIS", > enable_url($newsRow['newsSynopsis'])); > } > </code> > and this is how I try to loop the results in index.tpl.htm: > <code> > {section name=news loop=$newsRow} Simple!! You haven't done something like this: $_SMARTY->assign("newsRow", $newsRow /* or whatever */); Anyways, your way of doing this up there is somehow rather not so proper... (tell me if I'm wrong!!!) What you've got to do is load ALL the data into ONE array. Then do the {section} on it. Refer to {section} or {foreach} documentation on how to do so. BTW I usually do something like this: (this is using mysql API, but I think you know how to do it using PEAR) data = array(); while ($row = mysql_fetch_assoc($result)) $data[] = $row; $smarty->assign('data', $data); then do a {foreach} : {foreach from=$data item=row} Name: {$row.name}<br /> Address: {$row.address}<br /> {/foreach} (please anybody else tell me if the above code is wrong because I didn't have time to check it out) Salam hangat, Hendy Irawan - www.GaulDong.NET Kantor: (021) 5260467 [SoftVation] Kos: (021) 5261839 [kamar 3]

« previous php.smarty.general (#5569) next »