I want to set the structure in table product against plan, i want to show like that
+------------------+---------------+---------------+
| product1 | product2 | product3 |
+------------------+---------------+---------------+
| product1plan1 | product2plan1 | product3plan1 |
+------------------+---------------+---------------+
| prouduct1plan2 | product2plan2 | |
+------------------+---------------+---------------+
| product1plan3 | | |
+------------------+---------------+---------------+
but now it showing me like that
product1 | product1plan1 | product1plan2 product2 | product2plan1 | product2plan1
here is my code
<table>
<thead>
<tr>
<?php
foreach( $name as $product ) {
$c = 0;
foreach ($product as $key ) {
$c++;
?>
<th>
<?php echo $key['Product']['name']; ?>
<?php for($i = 0; $i < sizeof( $key['ProductPlan'] ); $i++ ) { ?>
<th class= 'packages' id = "<?php echo $key['Product']['name'], $key['ProductPlan'][$i]['product_plan_id']?>"
onclick = "document.getElementById('<?php echo $key['Product']['name']?>').value='<?php echo $key['ProductPlan'][$i]['product_plan_id']?>';"
>
<div product_name='<?php echo $key['Product']['slug']?>' class='amounts amount-<?php echo $key['Product']['slug']?>'>
<div class='tick'>
<?php echo $this->Html->image('tick.png', array('width'=>'25', 'height'=>'25'));?>
</div>
<div class='amount'>
<?php echo $key['ProductPlan'][$i]['name'];?> $
</div>
</div>
</th>
<?php } ?>
</th>
<?php } ?>
<?php } ?>
</tr>
</thead>
It is a little hard to figure this out without seeing the working example, but looking at the code in your question, you have a th tag inside a th tag, which is why you are seeing the results you are. I believe if you replace the inner th tag with a div tag, that should solve the issue.
However, the th tag is really supposed to be used for the table heading, or in your example, the product name. In order to do that, you will need 2 loops: 1 to create the table headings with the product names and a second to print out the plans (in a table cell in a row beneath your header).
Try this:
<table>
<thead>
<tr>
<th>
<?php
foreach ($name as $product) {
foreach ($product as $key) {
echo $key['Product']['name'];
}
}
?>
</th>
</tr>
</thead>
<tbody>
<tr>
<?php
foreach($name as $product) {
$c = 0;
?>
<?php
foreach ($product as $key) {
$c++;
?>
<td>
<?php for($i=0;$i<sizeof($key['ProductPlan']);$i++) { ?>
<div class = 'packages'
id = "<?php echo $key['Product']['name'],$key['ProductPlan'][$i]['product_plan_id']?>"
onclick = "document.getElementById('<?php echo $key['Product']['name']?>').value='<?php echo $key['ProductPlan'][$i]['product_plan_id']?>';"
>
<div product_name='<?php echo $key['Product']['slug']?>' class='amounts amount-<?php echo $key['Product']['slug']?>'>
<div class='tick'>
<?php echo $this->Html->image('tick.png', array('width'=>'25', 'height'=>'25'));?>
</div>
<div class='amount'>
<?php echo $key['ProductPlan'][$i]['name'];?> $
</div>
</div>
</div>
<?php }?>
</td>
<?php } ?>
<?php } ?>
</tr>
</tbody>
</table>