|
|
 |
Re: FN-FORUM: FW: Problem with Smarty yikes!
date posted 3rd February 2008 16:46
Chris Hanson wrote:
>
> Hey guys im having trouble with smarty wonder if any one could help - what
> it is im using the {foreach} loop in my template file like so:
>
> {foreach name=portfolio item=port from=$port_results}
>
>
> Website Name:
> {$port.website_name}
> Website URL: href="{$port.website_url}" target="_blank">{$port.website_url} />
> Languages/Tech Used:
> {$port.languages}
> Design: {$port.design}
> Comments: {$port.comments} />
>
>
> {/foreach}
>
> And the php code is getting the mysql data and putting it into an
> associative array but im getting results like this:
> /php code/
>
> $query = "SELECT * FROM `port_details`";
>
> $result = mysql_query($query);
>
> $port_results = mysql_fetch_assoc($result);
>
> $smarty->assign('port_results', $port_results);
>
> /php code/
>
> Website Name: 1
> Website URL: 1
> Languages/Tech Used: 1
> Design: 1
> Comments: 1
>
> Website Name: h
> Website URL: h
> Languages/Tech Used: h
> Design: h
> Comments: h
>
> I don't no what is going wrong here as when i write a simple assoc array it
> works but getting it from my db displays the above output any help would be
> appreciated thanks!
>
> Regards Chris
>
>
The foreach loop is expecting something along the lines of :
$port_results[0] = array("foo" => "bar");
what I believe you are doing is sending :
$port_results = array("foo" => "bar");
So in the code you have given the $port var is not a complete row, but
one item from that row.
Perhaps you mean to do something like this (but I haven't checked it) :
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
$port_results[] = $row;
}
$smarty->assign('port_results', $port_results);
Cheers
Wills
|
 |
|