php 难题 smarty循环
模板代码{foreachfrom=$goods_orderby_listitem=goods_orderby}<tr><tdalign="center">{$goods_...
模板代码
{foreach from =$goods_orderby_list item=goods_orderby}
<tr>
<tdalign="center">{$goods_orderby.goods_id}</td>
<tdalign="center">{$goods_orderby.goods_name}</td>
{foreach from =$category_list item=category}
<tdalign="center">{$goods_orderby[$category.id].number}</span></td>
{/foreach}
</tr>
{foreachelse}
<tr><tdcolspan="9">{$lang.no_records}</td></tr>
{/foreach}
这里{$goods_orderby[$category.id].number}要怎么改????? 展开
{foreach from =$goods_orderby_list item=goods_orderby}
<tr>
<tdalign="center">{$goods_orderby.goods_id}</td>
<tdalign="center">{$goods_orderby.goods_name}</td>
{foreach from =$category_list item=category}
<tdalign="center">{$goods_orderby[$category.id].number}</span></td>
{/foreach}
</tr>
{foreachelse}
<tr><tdcolspan="9">{$lang.no_records}</td></tr>
{/foreach}
这里{$goods_orderby[$category.id].number}要怎么改????? 展开
3个回答
展开全部
<?php
require_once "../smarty/libs/Smarty.class.php";
$smarty = new Smarty;
$smarty->left_delimiter = "{";
$smarty->right_delimiter = "}";
$smarty->template_dir = "./templates";
$smarty->compile_dir = "./templates_c";
$goods_orderby_list = array(
"1"=>array(
"1"=>array(
"number"=>"11"
),
"2"=>array(
"number"=>"12"
)
),
"2"=>array(
"1"=>array(
"number"=>"21"
),
"2"=>array(
"number"=>"22"
)
)
);
$category_list = array(
"1"=>array(
"id"=>"1"
),
"2"=>array(
"id"=>"2"
)
);
$smarty->assign("goods_orderby_list",$goods_orderby_list);
$smarty->assign("category_list",$category_list);
$smarty->display("one.tpl");
{foreach from =$goods_orderby_list item=goods_orderby}
<tr>
{foreach from =$category_list item=category}
<td align="center">{$goods_orderby[$category.id].number}</td>
{/foreach}
</tr>
{/foreach}
我试了,这样可以,输出:11 12 21 22
你那样写应该对的,不知道$goods_orderby_list是几维数组的,是三维数组是正确的;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询