Home  >  Article  >  Backend Development  >  如何在smarty里面的循环中进行assign

如何在smarty里面的循环中进行assign

WBOY
WBOYOriginal
2016-06-13 10:37:04872browse

怎么在smarty里面的循环中进行assign
这个是smarty里面的代码

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$i=0;$db->Query("brand_list","select * from `category` where `pid`='2' order by id");//总共有4个结果while($array = $db->GetArray("brand_list")){    $brand_list[] = $array;    $i++;    $wf->assign("i",$i);    //echo $i.',';}$wf->assign('brand_list',$brand_list);


这个是模板里面的代码
HTML code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->{foreach from=$brand_list item=list}    {$i},{/foreach} 


现在就是在php里面echo 一下的话输出的就是正确的结果:1,2,3,4,
但是在模板里面就是输出的4,4,4,4,

我知道可以在模板里面实现自加,这边只是举了个例子。
我想问的是怎么在php的循环里面去进行assign,从而能够使模板能够正常的输出我想要的东西。

不知道表达的够不够清楚。

------解决方案--------------------
$i=0;
$db->Query("brand_list","select * from `category` where `pid`='2' order by id");//总共有4个结果
$index = array();
while($array = $db->GetArray("brand_list")){
$brand_list[] = $array;
$i++;
$index[] = $i;
//echo $i.',';
}
$wf->assign("i",$index);
$wf->assign('brand_list',$brand_list);


{foreach from=$brand_list item=list key=key}
{$i[$key]},
{/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