I need to print on screen an HTML table that reaches its data looping various times over nested data. I fill a header for the table looping through my Quotes array and I fill a second header to the left of my table looping through the Items I need to see. The problem comes when I need to loop through the information of my table in this case my Prices list and print only the ones fitting both conditions. 1) To be an element from my Quotes array and 2) To be the Price that correspond to the exact Item on the left.
I get more or less <td>
tags than the ones I need and the data ends up outside the limits of my table.
I would really appreciate if you can give me any ideas how to approach this issue.
The structure of my Quotes array includes a nested array with the Prices like this
(int) 0 => array(
'Quote' => array(
'id' => '1',
),
'Price' => array(
(int) 0 => array(
'id' => '1',
'price' => '20.00',
'payment' => 'A',
),
(int) 1 => array(
'id' => '2',
'price' => '50.00',
'payment' => 'B',
)
),
'Order' => array());
and this is my actual code printing more tags than the ones needed
<table>
<tr>
<td colspan="2"><?php echo __('Order No.'); ?></td>
<td colspan="12"><?php echo __('List of Quotes'); ?></td>
</tr>
<tr>
<td colspan="2"><?php echo __('List of Item'); ?></td>
<?php foreach ($quotes as $quote): ?>
<td colspan="3"><?php echo __('Quote'); ?> <?php echo h($quote['Quote']['id']); ?></td>
<?php endforeach; ?>
</tr>
<tr>
<td><?php echo __('id'); ?></td>
<td><?php echo __('description'); ?></td>
<?php foreach ($quotes as $quote): ?>
<td><?php echo __('id'); ?></td>
<td><?php echo __('price'); ?></td>
<td><?php echo __('payment'); ?></td>
<?php endforeach; ?>
</tr>
<?php foreach ($items as $item):?>
<tr>
<td><?php echo h($item['Item']['id']); ?></td>
<td><?php echo h($item['Item']['descripcion']); ?></td>
<?php foreach ($quotes as $quote): ?>
<?php foreach ($quote['Price'] as $price): ?>
<?php if($price['item_id']==$item['Item']['id'] ): ?>
<td><?php echo h($price['item_id']); ?></td>
<td><?php echo h($price['quote_id']); ?></td>
<td><?php echo h($price['id']); ?></td>
<?php else: ?>
<td></td>
<td></td>
<td></td>
<?php endif; ?>
<?php endforeach; ?>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</table>