foreach使用

1. 读取记录
while($row=mysql_fetch_array($result))
{$record[]=array(
    'title'=>$row['title'],
 'body'=>$row['body'],);
}

$smarty->assign('yes', $record);//传说中的替换变量,即将$record赋给yes

 

2.在前台展示

{foreach item=news from=$yes}
{$news.title}:{$news.body}
<br>
{/foreach}

原文地址:https://www.cnblogs.com/zgaspnet/p/3270024.html