Re: passing result arrays to Smarty template

From: Date: Wed, 12 Jan 2005 18:48:51 +0000
Subject: Re: passing result arrays to Smarty template
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-12153@lists.php.net to get a copy of this message
Kathleen Krause-Thompson wrote:
Hello--I am trying to pass mysql result arrays to a Smarty template as one associative array. I have the code below, but it results in only 1 result row being passed to the template. How could every row be passed? I am grateful for any assistance. <?php $sql = "SELECT ORGANIZATION_ID, ORGANIZATION_NAME FROM ORGANIZATION";
$result = mysql_query($sql); while ($row = mysql_fetch_array($result)) { //$smarty->assign("organizations", array("ID" => $row[0], //"ORGANIZATION_NAME" => $row[1] )); $organizations[$row[0]] = $row[1]; $smarty->assign('organizations',$organisations); } ?>
{foreach from=$organizations key=ID item=ORGANIZATION_NAME}
       {$ID}   {$ORGANIZATION_NAME} <br>
{/foreach}
Using PEAR DB is even easiser $sql = "SELECT ORGANIZATION_ID, ORGANIZATION_NAME FROM ORGANIZATION"; $smarty->assign('organisations',$db->getAssoc($sql) );

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