php smarty模板引擎foreach循环显示不出来

这是数据库代码,我把数据倒腾到数组里去了: public function execute_dml2($sql){ $arr=array(); $res=mysql_query($sql); while($row=mysql_fetch_assoc($res)){ $arr[]=$row; } return $arr; }这是控制器代码: require_once "SqlHelper.class.php"; require_once "./libs/Smarty.class.php"; $SqlHelper= new SqlHelper(); $res2=$SqlHelper->execute_dml2("select * from blog_article order by article_id desc limit 0,2"); $Smarty= new Smarty(); $Smarty->assign("articlelist",$res2); $Smarty->display("articlelist.tpl");这是模板代码:<ul id="articlelist">{foreach from $articlelist item=articlelist}<li><a href="#">{$articlelist.article_title}</a></li>{/foreach}</ul>我是去博客文章的两条数据而已,担心是二维关联数组,这里我还用了两个foreach循环还是报错,

把 {foreach from $articlelist item=articlelist} 改成 {foreach from=$articlelist item="articleitem"}
把{$articlelist.article_title} 改成 {$articleitem.article_title}
改成这样的试试看,你这里 {foreach from $articlelist item=articlelist} 写法就有问题了
from 要等于 $articlelist from=$articlelist
item 值名不能与 输入多维数据名一样
最后 {foreach from=$articlelist item="articleitem"} 是 Smarty 2 的写法
Smarty 3 的写法是 {foreach $articlelist as $articleitem}
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网