Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Smarty在while循环中分配变量_Php_Smarty - Fatal编程技术网

Php Smarty在while循环中分配变量

Php Smarty在while循环中分配变量,php,smarty,Php,Smarty,我有以下PHP函数 while( $manufacturer2 = xtc_db_fetch_array($manufacturer_query2,true) ){ echo $manufacturer2['manufacturers_name'] = '<a class="PI_Manufacturer" href="'. xtc_href_link(FILENAME_DEFAULT, xtc_manufacturer_link($manufacturer2['manufacturers

我有以下PHP函数

while( $manufacturer2 = xtc_db_fetch_array($manufacturer_query2,true) ){
echo $manufacturer2['manufacturers_name'] = '<a class="PI_Manufacturer"
href="'. xtc_href_link(FILENAME_DEFAULT, xtc_manufacturer_link($manufacturer2['manufacturers_id'])) . '">' . $manufacturer2['manufacturers_name'] . '</a>';
}

在while循环中,但是当我在模板中调用变量时,我只得到1个名称,而不是2个或3个。在我的模板中,我使用foreach循环来获取所有值。有什么建议吗?

因为您使用一个变量来存储b值,这就是为什么您只得到一个值。尝试使用smarty数组分配值。

以下是我解决此问题的方法:

在while循环中创建了一个数组,并将每个项目放入其中:

while( $manufacturer2 = xtc_db_fetch_array($manufacturer_query2,true) ){
$os[] = $manufacturer2['manufacturers_name'] = '<a class="PI_Manufacturer" style="color: #990033" href="' . xtc_href_link(FILENAME_DEFAULT, xtc_manufacturer_link($manufacturer2['manufacturers_id'],$manufacturer2['manufacturers_name'])) . '">' . $manufacturer2['manufacturers_name'] . '</a><text class="PI_Manufacturer">;</text> ';
$info_smarty->assign('ALINK',$os);
}
while( $manufacturer2 = xtc_db_fetch_array($manufacturer_query2,true) ){
$os[] = $manufacturer2['manufacturers_name'] = '<a class="PI_Manufacturer" style="color: #990033" href="' . xtc_href_link(FILENAME_DEFAULT, xtc_manufacturer_link($manufacturer2['manufacturers_id'],$manufacturer2['manufacturers_name'])) . '">' . $manufacturer2['manufacturers_name'] . '</a><text class="PI_Manufacturer">;</text> ';
$info_smarty->assign('ALINK',$os);
}
{foreach item=authors from=$ALINK} 
{$authors}
{/foreach}