Usually I retrieve and return data from a database like this:
$sql = "SELECT * FROM users";
$res = mysql_query($sql);
while ($row = mysql_fetch_assoc($res)) {
echo $row['id'];
echo $row['name'];
}
But how to return the data using Smarty?
I think, I have to assign $row:
$smarty->assign('row', $row);
$smarty->display('search.tpl');
But I’m not sure how to actually display it. This doesn’t work:
{foreach from=$row item=item}
{$item}
{/foreach}
You should use
{$row.id}and{$row.name}in your template (without foreach).Upd. If you want to get all rows:
In template: