>  기사  >  백엔드 개발  >  如何在smarty里面的循环中进行assign

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

WBOY
WBOY원래의
2016-06-13 13:16:19802검색

怎么在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}
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.