您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

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

2025/2/14 18:03:36发布29次查看
怎么在smarty里面的循环中进行assign
这个是smarty里面的代码
php code$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{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}
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product