桌子
Tables
Product Plan ProductPlan
id |name id |name id | product_id | plan_id
1 aplha 1 a 1 1 2
2 bravo 2 b 2 4 c
3 charlie 4 c
4 delta
我想根据它的相关 id 查看数据,例如,如果产品有两个计划,它将在该产品的列表中。像那样
alpha | delta |
a c
b
查看代码是
<table>
<thead>
<tr>
<?php foreach ($p as $ps){?>
<th>
<?php echo __l($ps['Product']['name']);?>
</th>
<?php }?>
</tr>
</thead>
<tbody>
<?php foreach ($p as $p1){
foreach($p1['Plan'] as $plan){
debug($plan);
?>
<tr>
<td>
<?php echo __l($plan['name']);?>
</td>
</tr>
<?php }
}?>
</tbody>
当我调试 $p1 数组时,
array(
'Product' => array(
'product_id' => '1',
'name' => 'Event Manager',
'slug' => 'event-manager',
'is_visible' => true
),
'Plan' => array(
(int) 0 => array(
'plan_id' => '1',
'name' => 'FREE',
'description' => '30 Days Trial',
'amount' => '0.00',
'expiry_days' => '30',
'created' => '2012-01-12 16:51:21',
'modified' => '2012-01-12 16:51:22',
'PlansProduct' => array(
'plan_product_id' => '1',
'product_id' => '1',
'plan_id' => '1'
)
),
(int) 1 => array(
'plan_id' => '2',
'name' => 'BRONZE',
'description' => '60 Days Trial',
'amount' => '10.00',
'expiry_days' => '60',
'created' => '2012-01-12 16:52:24',
'modified' => '2012-01-12 16:52:25',
'PlansProduct' => array(
'plan_product_id' => '2',
'product_id' => '1',
'plan_id' => '2'
)
)
)
)
我怎样才能做到这一点?提前致谢。