How to perform assign in a loop inside a smarty

Source: Internet
Author: User
How to do assign in the loop inside the Smarty
This is the code inside the Smarty.
PHP Code
   $i =0; $db->query ("Brand_list", "SELECT * from ' category ' where ' pid ' = ' 2 ' ORDER by id");//Total 4 results while ($array = $db GetArray ("Brand_list")) {    $brand _list[] = $array;    $i + +;    $WF->assign ("i", $i);    echo $i. ', ';} $WF->assign (' brand_list ', $brand _list);

This is the code inside the template.
   {foreach from= $brand _list item=list}    {$i},{/foreach}

Now it is in PHP that echo words output is the correct result: 1,2,3,4,
But inside the template is the output of the 4,4,4,4,

I know I can do it in a template, and this is just an example.
What I want to ask is how to do the assign in the PHP loop, so that the template can output what I want normally.

I do not know the expression is not clear enough.

$i = 0;
$db->query ("Brand_list", "SELECT * from ' category ' where ' pid ' = ' 2 ' ORDER by id");//Total 4 results
$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]},
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

    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.