我想用php对这个表的行进行求和

我想用php对这个表的行进行求和,php,Php,请有人能帮我用php求和吗 月 A. B C D E F G 2011 一月 0 0 0 0 0 0 0 二月 1. 1. 0 0 0 0 0 十一月 0 1. 0 0 0 0 0 十二月 4. 4. 0 0 1. 1. 0 全年总数 5. 6. 0 0 1. 1. 0 年份占总额的百分比 2012年 一月 1. 1. 0 0 2. 1. 0 二月 0 0 0 0 0 0 0 十一月 25 20 1. 4. 4. 2. 0 十二月 26 6. 3. 1. 1. 3. 0 全年总数 52 27

请有人能帮我用php求和吗

月 A. B C D E F G 2011 一月 0 0 0 0 0 0 0 二月 1. 1. 0 0 0 0 0 十一月 0 1. 0 0 0 0 0 十二月 4. 4. 0 0 1. 1. 0 全年总数 5. 6. 0 0 1. 1. 0 年份占总额的百分比 2012年

一月 1. 1. 0 0 2. 1. 0 二月 0 0 0 0 0 0 0 十一月 25 20 1. 4. 4. 2. 0 十二月 26 6. 3. 1. 1. 3. 0 全年总数 52 27 4. 5. 7. 6. 0 年份占总额的百分比

您可以将结果格式化为关联数组,并循环以获得预期的表视图

向你展示一种非常古老的方式

<!--

    <?php
    $array = array(
        '2011' => array(
            'January' => array(0, 0, 1, 0, 3, 0, 1),
            'February' => array(3, 5, 0, 2, 1, 0, 0),
            'March' => array(0, 3, 0, 3, 0, 1, 2),
        ),
        '2012' => array(
            'January' => array(3, 5, 0, 2, 1, 0, 0),
            'February' => array(0, 3, 0, 3, 0, 1, 2),
            'March' => array(0, 0, 1, 0, 3, 0, 1),
        )
    );
    ?>

    <table width="100%" border="1" cellspacing="1" cellpadding="1">
        <tbody>
            <tr>
                <th scope="row">month</th>
                <th>A</th>
                <th>B</th>
                <th>C</th>
                <th>D</th>
                <th>E</th>
                <th>F</th>
                <th>G</th>
            </tr>

            <?php
            foreach ($array as $year => $months) {
                ?>
                <tr>
                    <th colspan="9"><?php echo $year; ?></th>
                </tr>

                <?php
                $sum1 = 0;
                $sum2 = 0;
                $sum3 = 0;
                $sum4 = 0;
                $sum5 = 0;
                $sum6 = 0;
                $sum7 = 0;
                foreach ($months as $month => $values) {
                    ?>
                    <tr>
                        <td><?php echo $month; ?></td>
                        <td><?php echo $values[0]; ?></td>
                        <td><?php echo $values[1]; ?></td>
                        <td><?php echo $values[2]; ?></td>
                        <td><?php echo $values[3]; ?></td>
                        <td><?php echo $values[4]; ?></td>
                        <td><?php echo $values[5]; ?></td>
                        <td><?php echo $values[6]; ?></td>
                    </tr>
                    <?php
                    $sum1 = $sum1 + $values[0];
                    $sum2 = $sum2 + $values[1];
                    $sum3 = $sum3 + $values[2];
                    $sum4 = $sum4 + $values[3];
                    $sum5 = $sum5 + $values[4];
                    $sum6 = $sum6 + $values[5];
                    $sum7 = $sum7 + $values[6];
                }
                ?>
                <tr>
                    <th>Year Total</th>
                    <th><?php echo $sum1; ?></th>
                    <th><?php echo $sum2; ?></th>
                    <th><?php echo $sum3; ?></th>
                    <th><?php echo $sum4; ?></th>
                    <th><?php echo $sum5; ?></th>
                    <th><?php echo $sum6; ?></th>
                    <th><?php echo $sum7; ?></th>
                </tr>
                <tr>
                    <th>Year % of grand Total</th>
                    <th>&nbsp;</th>
                    <th>&nbsp;</th>
                    <th>&nbsp;</th>
                    <th>&nbsp;</th>
                    <th>&nbsp;</th>
                    <th>&nbsp;</th>
                    <th colspan="2">&nbsp;</th>
                </tr>
                <?php
            }
            ?>
        </tbody>
    </table>

请显示您的代码,您迄今为止已经尝试过请显示您迄今为止所做的工作。我已经收集了arrayPlease中的值,请在你的问题中添加PHP代码,包括mysql_query等。游戏超出了这个范围。请检查第二个代码片段,看看完整的游戏。谢谢broas,我说过最好在关联数组中获取所有结果,然后为您的视图进行处理。这样代码将更有条理,更易于调试