Reputation: 616
So this is my foreach-loop
foreach($statusMessageResult as $row){
$row['username']=$db->getUsername($db->getUserNameById($row['posterID']));
$results[] = $row;
echo "Status from: " . $row['username'] . " ID: " . $row['statusID'] . "<br>" . $row['dateTime'];
}
Which works without problems. But now I want to have the same in smarty. So I thought I'm going to do this in the .php file
$smarty->assign('results', $results);
and this in the .html file
{foreach from=$results item=statusID}
id: {$statusID}<br>
{/foreach}
But it tells me
Notice: Array to string conversion in F:\xampp\htdocs\FinalYear\smarty\templates_c\ab89063f543bf0a8fe20c45b89aad63b616cd7c5.file.home.html.php on line 86
Array
Well the problem seems clear: I have an array and want to use it as a string, whiich isn't allowed. But how can I solve it ?
Upvotes: 0
Views: 457
Reputation: 32820
Try this :
{foreach from=$results item=result}
id: {$result.statusID}<br>
{/foreach}
If you want user name : {$result.username}
Ref: http://www.smarty.net/docsv2/en/language.function.foreach
Upvotes: 2
Reputation: 3088
statusID
is an array, get value by key name like that:
{foreach from=$results item=statusID}
id: {$statusID.username}<br>
{/foreach}
Upvotes: 0
Reputation: 2222
$statusID
seems to be an array :)
changing
{foreach from=$results item=statusID}
id: {$statusID}<br>
{/foreach}
to
{foreach from=$results item=statusID}
id: {$statusID['statusID']}<br>
{/foreach}
should solve it
Upvotes: -1