如何在smarty裡面的迴圈中進行assign

來源:互聯網
上載者:User
怎麼在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}
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.