RE: [SMARTY] give smarty tpl file a php associative array?
| From: | Rob Schultz | Date: | Fri, 02 May 2003 09:04:39 +0000 |
| Subject: | RE: [SMARTY] give smarty tpl file a php associative array? | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-9445@lists.php.net to get a copy of this message | ||
Actually i would write it up like this..
<?php
mysql_connect($host, $mysqluser, $mysqlpwd)||
die(mysql_error());
mysql_select_db($db)||die(mysql_error());
$query=mysql_query("select * from members");
$smarty=new smarty;
while($member=mysql_fetch_array($query)){
//wanna add this member array to the array already in smarty now.
$smarty->append("member",$member);
}
$smarty->display("index.tpl");
?>
now in index.tpl:
<body>
{section name=member_show loop=$member}
{$member[member_show].company}
{$member[member_show].address1}
{*so on through the loop*}
{/section}
so it actually is priting the proper index in the array.
Rob
> -----Original Message-----
> From: Prince [mailto:friendly@kaltelnet.net]
> Sent: Friday, May 02, 2003 1:06 PM
> To: smarty-general@lists.php.net
> Subject: [SMARTY] give smarty tpl file a php associative array?
>
>
> hi
>
> have been trying to get this problem fixed for a while now
> but still dont know quite how to fix it...
>
> i have an array: $member
> its assigned in the index.php file of the template file by
> doing a mysql query to get all members in an array:
> <?php
> mysql_connect($host, $mysqluser, $mysqlpwd)||
> die(mysql_error());
> mysql_select_db($db)||die(mysql_error());
>
> $query=mysql_query("select * from members");
>
> while($member=mysql_fetch_array($query)){
> //not sure what to do here since php gives me an associative
> //array already
> }
> $smarty=new smarty;
> $smarty->assign($member,array());//i think but not sure...
> $smarty->display(index.tpl);
> ?>
> now in index.tpl:
> <body>
> {section name=member_show loop=$member}
> {$member.company}
> {$member.address1}
> {*so on through the loop*}
> {/section}
> how should i fix this so it works? keep getting parse error on it...
>
>