Re: [SMARTY] passing result arrays to Smarty template
| From: | Monte Ohrt | Date: | Wed, 12 Jan 2005 17:56:33 +0000 |
| Subject: | Re: [SMARTY] passing result arrays to Smarty template | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-12152@lists.php.net to get a copy of this message | ||
use $smarty->append() instead of $smarty->assign()
You are overwriting the assigned value on each iteration.
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] ));} ?> {foreach from=$organizations key=ID item=ORGANIZATION_NAME}{$ID} {$ORGANIZATION_NAME} <br>{/foreach}