Php Smarty在while循环中分配变量
我有以下PHP函数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
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}