如何在smarty里面的循环中进行assign
怎么在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}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

List operation //Insert a value from the head of the list. $ret=$redis->lPush('city','guangzhou');//Insert a value from the end of the list. $ret=$redis->rPush('city','guangzhou');//Get the elements in the specified range of the list. 0 represents the first element of the list, -1 represents the last element, and -2 represents the penultimate element. $ret=$redis->l

Title: Example of using the Array.Sort function to sort an array in C# Text: In C#, array is a commonly used data structure, and it is often necessary to sort the array. C# provides the Array class, which has the Sort method to conveniently sort arrays. This article will demonstrate how to use the Array.Sort function in C# to sort an array and provide specific code examples. First, we need to understand the basic usage of the Array.Sort function. Array.So

1: JSONArray to ListJSONArray string to List//Initialize JSONArrayJSONArrayarray=newJSONArray();array.add(0,"a");array.add(1,"b");array.add(2,"c") ;Listlist=JSONObject.parseArray(array.toJSONString(),String.class);System.out.println(list.to

In PHP, there are many powerful array functions that can make array operations more convenient and faster. When we need to combine two arrays into an associative array, we can use PHP's array_combine function to achieve this operation. This function is actually used to combine the keys of one array as the values of another array into a new associative array. Next, we will explain how to use the array_combine function in PHP to combine two arrays into an associative array. Learn about array_comb

When programming in PHP, we often need to merge arrays. PHP provides the array_merge() function to complete array merging, but when the same key exists in the array, this function will overwrite the original value. In order to solve this problem, PHP also provides an array_merge_recursive() function in the language, which can merge arrays and retain the values of the same keys, making the program design more flexible. array_merge

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

Method to convert list to numpy: 1. Use the numpy.array() function. The first parameter of the function is a list object, which can be a one-dimensional or multi-dimensional list; 2. Use the numpy.asarray() function, which will try its best to Use the data type of the input list; 3. Use the numpy.reshape() function to convert the one-dimensional list into a multi-dimensional NumPy array; 4. Use the numpy.fromiter() function, the first parameter of the function is an iterable object.

Example In this example, we first look at the usage of list.sort() before continuing. Here, we have created a list and sorted it in ascending order using sort() method - #CreatingaListmyList=["Jacob","Harry","Mark","Anthony"]#DisplayingtheListprint("List=",myList)#SorttheListsinAscendingOrdermyList .sort(
