Heim  >  Artikel  >  Backend-Entwicklung  >  如何在smarty里面的循环中进行assign

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

WBOY
WBOYOriginal
2016-06-13 10:37:04869Durchsuche

怎么在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}
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn