doumuyu0837 2013-07-19 16:18
浏览 33

打印HTML表格,迭代3个循环PHP

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>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 pyqt5tools安装失败
    • ¥15 mmdetection
    • ¥15 nginx代理报502的错误
    • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
    • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
    • ¥100 描述一下元器件的基本功能,pcba板的基本原理
    • ¥15 STM32无法向设备写入固件
    • ¥15 使用ESP8266连接阿里云出现问题
    • ¥15 BP神经网络控制倒立摆
    • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果