Php 在以下场景中,如何在Smarty模板中打印关联数组数据?
我在PHP中有一个名为Php 在以下场景中,如何在Smarty模板中打印关联数组数据?,php,arrays,smarty,associative-array,Php,Arrays,Smarty,Associative Array,我在PHP中有一个名为$all_products的数组,如下所示: Array ( [0] => Array ( [id] => 5 [code] => Ch1212 [name] => Chesse [manufacturer_id] => 33 [product_type_id] => 35
$all_products
的数组,如下所示:
Array
(
[0] => Array
(
[id] => 5
[code] => Ch1212
[name] => Chesse
[manufacturer_id] => 33
[product_type_id] => 35
[packaging_type_id] => 4
[created_at] => 1397816303
[updated_at] => 1397827441
[manufacturer] => Array
(
[id] => 33
[company_name] => Eywa Solutions
[email] => shweta.jain@creatywa.com
[domain_id] => 14
[created_at] => 1397481239
[updated_at] => 1397672832
)
[product_type] => Array
(
[id] => 35
[product_type] => Milk
[created_at] => 1397816259
[updated_at] => 1397816259
)
[packaging_type] => Array
(
[id] => 4
[packaging_type] => Pack
[bottles_per_pack] => 6
[created_at] => 1397641872
[updated_at] => 1397672081
)
)
[1] => Array
(
[id] => 8
[code] => LAP201
[name] => Laptop an
[manufacturer_id] => 41
[product_type_id] => 32
[packaging_type_id] => 5
[created_at] => 1398088150
[updated_at] => 1398088150
[manufacturer] => Array
(
[id] => 41
[company_name] => Dell
[email] => dell.india@test.com
[domain_id] => 8
[created_at] => 1397641666
[updated_at] => 1397672612
)
[product_type] => Array
(
[id] => 32
[product_type] => Rum
[created_at] => 1397656687
[updated_at] => 1397672183
)
[packaging_type] => Array
(
[id] => 5
[packaging_type] => Case
[bottles_per_pack] => 12
[created_at] => 1397672031
[updated_at] => 1397672031
)
)
)
上述阵列已分配给smarty模板。
现在我必须在smarty模板中打印上面的数组。下面是我试图在smarty模板中打印数组的代码,但它只正确显示了两个字段的数据,即代码和名称。您能否帮助我更正在smarty模板中打印其余阵列数据时出现的错误
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>Sr. No.</th>
<th>Manufacturer</th>
<th>Product Code</th>
<th>Product Name</th>
<th>Product Type</th>
<th>Packaging Type</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{assign var='i' value=1}
{section name=product loop=$all_products}
<tr>
<td>{$i}</td>
<td>{$all_products[product][manufacturer].comapany_name}</td>
<td>{$all_products[product].code}</td>
<td>{$all_products[product].name}</td>
<td>{$all_products[product][product_type].product_type}</td>
<td>{$all_products[product][packaging_type].packaging_type}</td>
<td align="center"><a href="{$control_url}products.php?op=edit&id={$all_products[product].id}" ><i class="icon-pencil"></i></a> <a href="{$control_url}products.php?op=delete&id={$all_products[product].id}" onClick="return ConfirmDelete()"><i class="icon-trash"></i></a></td>
</tr>
{assign var='i' value=$i+1}
{/section}
</tbody>
</table>
高级专员。
制造商
产品代码
品名
产品类型
包装类型
行动
{assign var='i'value=1}
{节名=产品循环=$all_products}
{$i}
{$all_products[产品][制造商].comapany_name}
{$all_products[product].code}
{$all_products[product].name}
{$all_products[product][product_type]。product_type}
{$all_products[产品][包装类型].包装类型}
{assign var='i'值=$i+1}
{/section}
从上述代码中,以下两条语句正确显示了相关数据,其他行不显示任何内容:
<td>{$all_products[product].code}</td>
<td>{$all_products[product].name}</td>
{$all_产品[product].code}
{$all_products[product].name}
因此,请帮助我正确显示其他数据。请尝试以下代码:
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>Sr. No.</th>
<th>Manufacturer</th>
<th>Product Code</th>
<th>Product Name</th>
<th>Product Type</th>
<th>Packaging Type</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{assign var='i' value=1}
{section name=product loop=$all_products}
<tr>
<td>{$i}</td>
<td>{$all_products[product].manufacturer.company_name}</td>
<td>{$all_products[product].code}</td>
<td>{$all_products[product].name}</td>
<td>{$all_products[product].product_type.product_type}</td>
<td>{$all_products[product].packaging_type.packaging_type}</td>
<td align="center"><a href="{$control_url}products.php?op=edit&id={$all_products[product].id}" ><i class="icon-pencil"></i></a> <a href="{$control_url}products.php?op=delete&id={$all_products[product].id}" onClick="return ConfirmDelete()"><i class="icon-trash"></i></a></td>
</tr>
{assign var='i' value=$i+1}
{/section}
</tbody>
</table>
高级专员。
制造商
产品代码
品名
产品类型
包装类型
行动
{assign var='i'value=1}
{节名=产品循环=$all_products}
{$i}
{$all_products[product].manufacturer.company_name}
{$all_products[product].code}
{$all_products[product].name}
{$all_products[product].product_type.product_type}
{$all_products[product]。包装类型。包装类型}
{assign var='i'值=$i+1}
{/section}
您正在以错误的方式分析数组。我现在已经改正了。它应该对你有用。干杯