无法设置嵌套表。来自cakephp控制器的数据

时间:2016-04-19 14:01:00

标签: php html mysql cakephp foreach

我正在构建一个显示由

组成的行的表

年月总计(总和())

当您单击该行时,引导程序会展开它并显示一个嵌套表,其中包含与该月份和年份相关的更详细的数据行。

我相信我的数据来自控制器。 我需要进行查询以获得年,月和总和()每月的总数。

然后我做一个find()来获取子行。

它们全部传递给totalResiduals数组。

我的html / view看起来像这样

<div id="residuals" class="tab-pane">
            <table class="table table-striped-yellow table-bordered table-condensed">
                <thead>
                    <th>Year</th>
                    <th>Month</th>
                    <th>Total</th>
                </thead>
                <?php foreach($totalResiduals as $year => $monthResiduals): ?>
                    <?php foreach($monthResiduals as $month => $residuals): ?>
                    <tr data-toggle="collapse" data-parent="#accordion" href="#<?php echo $month; ?>" aria-expanded="false" style="cursor:pointer;">
                        <td><?php echo $year; ?></td>
                        <td><?php echo $month; ?></td>
                        <td><?php echo $residuals['paidTotal'];?></td>
                    </tr>
                    <tr id="<?php echo $month; ?>" class="collapse">
                        <td>
                            <table>
                                <thead>
                                    <th>Product Type</th>
                                    <th>Product Group</th>
                                    <th>Volume</th>
                                    <th>Paid</th>
                                </thead>
                                <?php foreach($residuals['residuals']  as $residual); ?>
                                    <tr>
                                        <td><?php echo $residual['product_type'] ?></td>
                                        <td><?php echo $residual['product_group'] ?></td>
                                        <td><?php echo $residual['volume'] ?></td>
                                        <td><?php echo $residual['paid'] ?></td>
                                    </tr>
                                <?php endforeach; ?>
                            </table>
                        </td>
                    </tr>
                    <?php endforeach; ?>

            </table>

最终发生的事情是,这些行最终会以折叠的嵌套行结束。最初将显示1行,单击它,打开1个子/嵌套行。单击它,打开1个主行,但在该子行中嵌套/折叠。

我想要发生的事情看起来像这样:

Year Month Total
2015 4     $30
   Type    Group   Volume Paid
   Product Product $0.00  $10.00
   Product Product $0.00  $10.00
   Product Product $0.00  $10.00

2015 5     $50
   Type    Group   Volume Paid
   Product Product $0.00  $25.00
   Product Product $0.00  $25.00

我假设我的错误在我看来,所以请让我知道我可以提供的其他信息,我已经遗漏了。

这是我的数据的print_r

Array

[2015] => Array
    (
        [1] => Array
            (
                [paidTotal] => 11.47
                [residuals] => Array
                    (
                        [0] => Array
                            (
                                [product_type] => HRV Residuals
                                [product_group] => HRV Residuals
                                [volume] => 0.00
                                [paid] => 11.47
                            )

                    )

            )

        [2] => Array
            (
                [paidTotal] => 5.77
                [residuals] => Array
                    (
                        [0] => Array
                            (
                                [product_type] => HRV Residuals
                                [product_group] => HRV Residuals
                                [volume] => 0.00
                                [paid] => 5.77
                            )

                    )

            )

        [4] => Array
            (
                [paidTotal] => 30.47
                [residuals] => Array
                    (
                        [0] => Array
                            (
                                [product_type] => HRV Residuals
                                [product_group] => HRV Residuals
                                [volume] => 0.00
                                [paid] => 12.06
                            )

                        [1] => Array
                            (
                                [product_type] => HRV Residuals
                                [product_group] => HRV Residuals
                                [volume] => 0.00
                                [paid] => 5.83
                            )

                        [2] => Array
                            (
                                [product_type] => HRV Residuals
                                [product_group] => HRV Residuals
                                [volume] => 0.00
                                [paid] => 12.58
                            )

                    )

            )

提前致谢,

史蒂芬

1 个答案:

答案 0 :(得分:0)

乍一看,不应该阻止

<tr data-toggle="collapse" data-parent="#accordion" href="#<?php echo $month; ?>" aria-expanded="false" style="cursor:pointer;">
                        <td><?php echo $year; ?></td>
                        <td><?php echo $month; ?></td>
                        <td><?php echo $residuals['paidTotal'];?></td>
                    </tr>

,不在此

<?php foreach($monthResiduals as $month => $residuals): ?>

,就像

<?php foreach($totalResiduals as $year => $monthResiduals): ?>
<tr data-toggle="collapse" data-parent="#accordion" href="#<?php echo $month; ?>" aria-expanded="false" style="cursor:pointer;">
                        <td><?php echo $year; ?></td>
                        <td><?php echo $month; ?></td>
                        <td><?php echo $residuals['paidTotal'];?></td>
                    </tr>
                    <?php foreach($monthResiduals as $month => $residuals): ?>