Home  >  Article  >  Backend Development  >  新人请问一个smarty有关问题

新人请问一个smarty有关问题

WBOY
WBOYOriginal
2016-06-13 10:18:21796browse

新人请教一个smarty问题
问题大概是这样子

从数据库获取最新的5条信息,每条信息有5个字段(id,name,cont,job,date),但只通过smarty显示其中的3个字段(cont,name,date),求解在tpl中该怎么写,为什么我循环出来的5条信息全是一样的(第5条)

我是这样写的
*********contro******
for ($i=0;$i $row=$page->res_array[$i]; //这里获取的全部字段
$smarty->assign("arr",$row);
}
**********tpl*******
{foreach from=$arr item=item1}


{$arr.cont}{$arr.name}于{$arr.date}{/foreach}

------解决方案--------------------
*********contro******
$arr = array();
for ($i=0;$i$row=$page->res_array[$i]; //这里获取的全部字段
$arr[] = $row;
}
$smarty->assign("arr",$arr);
**********tpl*******
{foreach from=$arr item=item1}
{$arr.cont}{$arr.name}于{$arr.date}{/foreach}
------解决方案--------------------
楼上的也错了
只要把$smarty->assign("arr",$row);这句放在循环外面就可以,不要$arr[] = $row;

{foreach from=$arr item=item1}
{item1.cont}{item1.name}于{item1.date}{/foreach}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP 安装解决方法Next article:php post提交。有关问题