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.
HTML Code
{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.
------Solution--------------------
$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]},
{/foreach}