Home > Archive > PHP Smarty Templates > January 2005 > passing result arrays to Smarty template
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
passing result arrays to Smarty template
|
|
| Kathleen Krause-Thompson 2005-01-12, 4:03 pm |
| 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}
| |
| pete M 2005-01-12, 4:03 pm |
| 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) );
|
|
|
|
|