-3

我想在新建和更新类别下显示一个列表,并单独计算新建和更新的总和。还需要总计显示。
这是MySql查询

SELECT * FROM motor WHERE DATE_FORMAT(date, '%Y %m') = DATE_FORMAT('$selected_year-$selected_month-01', '%Y %m') ORDER BY isnew ASC, date ASC

我已将 New 和 Renew 分开,但不能取列的总和。
这是PHP代码

    <?php
    if (empty($selected_m_q)){
        echo "<tr><td colspan='7'>$message</td></tr>";
    }else {
        $previous_staus = "";
        $type = "";
        while ($current_m_data = mysql_fetch_assoc($selected_m_q)){
            //var_dump ($current_m_data);
            $status = $current_m_data['isnew'];
            if ($status != $previous_staus){
                if ($status == 1){$type="New";}
                if ($status == 2){$type="Renew";}
                echo "<tr><td colspan='7'>status : $type</td></tr>";
                $previous_staus = $status;
            }
?>
<tr>
    <td><?php echo $current_m_data['date']; ?></td>
    <td><?php echo $current_m_data['policy_no']; ?></td>
    <td><?php echo $current_m_data['vnumber']; ?></td>
    <td><?php echo $current_m_data['name']; ?></td>
    <td align="right"><?php echo $current_m_data['gpremium']; ?></td>
    <td align="right"><?php echo $current_m_data['premium']; ?></td>
    <td><a href="edit-data-m.php?id=<?php echo $current_m_data['id']; ?>">Edit</a> | 
        <!--<input type="button" id="<?php //echo $current_m_data[id]; ?>" class="delete" value="Delete" >-->
        <a href="#" id="<?php echo $current_m_data['id']; ?>" class="delete">Delete</a>
    </td>
</tr>
<?php
        }
    }
?>

我想做的是在 New 和 Renew 下显示溢价栏的总数。在底部应该显示新的和更新的总数。
谁可以帮我这个事?

工作台电机有以下几列

id, date, policy_no, vnumber, name, address, expected, gpremium, premium, contact_detail, isnew

我已经尝试过计算,但只有我才能得到新的总数。

我的要求是这样的(在表格中显示)

New
新状态的少数数据行
New
Renew
的保费字段总数 续订状态下的少数数据行 Renew
的保费字段
总数 然后总计

如果我在这里写得不好,我很抱歉。这是我的第一个。

4

1 回答 1

0

在您的循环中,您可以只保留总数的运行计数....

 <?php
    if (empty($selected_m_q)){
        echo "<tr><td colspan='7'>$message</td></tr>";
    }else {
  >>>>  $previous_status = 1;
        $type = "";
  >>>>  $subTotal = 0;
  >>>>  $grandTotal = 0;
        while ($current_m_data = mysql_fetch_assoc($selected_m_q)){
            //var_dump ($current_m_data);
            $status = $current_m_data['isnew'];
            if ($status != $previous_staus){

>>>>>                
        ?>
            <tr> <td></td><td></td><td></td><td></td> 
                 <td><?= $subTotal ?></td> 
                 <td></td><td></td><td></td>
            </tr>
        <?php
            $subTotal = 0;
<<<<<

                if ($status == 1){$type="New";}
                if ($status == 2){$type="Renew";}
                echo "<tr><td colspan='7'>status : $type</td></tr>";
                $previous_staus = $status;
            }

  >>>>      $subTotal += $current_m_data['premium'];
  >>>>      $grandTotal += $current_m_data['premium'];
?>
<tr>
    <td><?php echo $current_m_data['date']; ?></td>
    <td><?php echo $current_m_data['policy_no']; ?></td>
    <td><?php echo $current_m_data['vnumber']; ?></td>
    <td><?php echo $current_m_data['name']; ?></td>
    <td align="right"><?php echo $current_m_data['gpremium']; ?></td>
    <td align="right"><?php echo $current_m_data['premium']; ?></td>
    <td><a href="edit-data-m.php?id=<?php echo $current_m_data['id']; ?>">Edit</a> | 
        <!--<input type="button" id="<?php //echo $current_m_data[id]; ?>" class="delete" value="Delete" >-->
        <a href="#" id="<?php echo $current_m_data['id']; ?>" class="delete">Delete</a>
    </td>
</tr>
<?php
        }
?>
<tr> <td></td><td></td><td></td><td></td> 
     <td><?= $grandTotal ?></td> 
     <td></td><td></td><td></td>
</tr>
<?php
    }
?>
于 2013-05-30T13:33:27.923 回答