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}

posted on 2013-08-20 13:36  张扬个性,敢为天下先  阅读(404)  评论(2编辑  收藏  举报