0

我使用以下代码创建了 php 报告。它工作正常。但我的问题是对数据示例进行分组

# Date          Code   Name       Rate  Qty  Amount# 
 15.01.2011     0001   Milk       4.01  50    200.50
 15.01.2011     0125   Choklet   30.00  10    300.00
 15.01.2011     0241   Drink     12.50  12    150.00
 16.01.2011     5461   Meat      35.07  10    350.75
 16.01.2011     4587   Fish      17.80   5     89.00
                                    total    1090.25     

如果我将日期范围从 15.01.2011 到 16.01.2011,它会在 php 页面中显示,如下所示。但如果我选择日期范围为 15.01.2011 到 16.01.2011,我需要如下所示

请帮助我

 # Date          Code   Name       Rate  Qty  Amount# 
 15.01.2011     0001   Milk       4.01  50    200.50
 15.01.2011     0125   Choklet   30.00  10    300.00
 15.01.2011     0241   Drink     12.50  12    150.00
                             subtotal         650.50
 16.01.2011     5461   Meat      35.07  10    350.75
 16.01.2011     4587   Fish      17.80   5     89.00
                             subtotal         439.75 
                             grand total     1090.25 

这是我的代码

<?php //include '../templete/header.php'; ?>
    <script language="javascript" type="text/javascript">
     function printFunction(){
     window.print();
     }
    </script>
    <script language="javascript" type="text/javascript">
    function PrintGridData() {
        var prtGrid = document.getElementById('<%=txtDocNo%>');
        prtGrid.border = 0;
                            var prtwin = window.open('','PrintGridViewData','left=100,top=100,width=1000,height=1000,tollbar=0,scrollbars=1,status=0,resizable=1');
        prtwin.document.write(prtGrid.outerHTML);
        prtwin.document.close();
        prtwin.focus();
        prtwin.print();
        prtwin.close();
     </script>
    <table width="100%" align="center" cellpadding="4" cellspacing="1" class=tbl_table">
      <tr>
        <td class="tbl_header">SO Date</td>
        <td class="tbl_header">MV CODE</td>
        <td class="tbl_header">MV NAME</td>
        <td class="tbl_header">RATE</td>
        <td class="tbl_header">SUPP.QTY</td>
        <td class="tbl_header">AMT</td>
    </tr>
    <?php 
      if(isset($stmt))
        { 
            while($row = $stmt->fetch())
        {?>
<tr>
<td class="tbl_content"><?php echo date("d-m-Y", strtotime($row['SODate']));?></td>
  <td class="tbl_content"><?php echo $row['MVCode'];?></td>
  <td class="tbl_content"><?php echo $row['MVName'];?></td>
  <td class="tbl_content_right"><?php echo number_format($row['Rate'],2) ;?></td>
  <td class="tbl_content_right"><?php echo number_format($row['Qty']) ;?></td>
  <td class="tbl_content_right"><?php echo number_format($row['BalAmt'],2) ;?></td>
  </tr>
<?php 
    $balamt+=$row['BalAmt'];
    $qty+=$row['Qty'];
}}?> 

      <tr><td colspan="9"><hr /></tr>
      <tr>  
      <td colspan="5"></td>
      <td class="tbl_content_total">  <?php echo number_format($qty);?></td>
      <td class="tbl_content_total">  <?php echo number_format($rtnqty);?></td>
      <td class="tbl_content_total">  <?php echo number_format($balqty);?></td>
      <td class="tbl_content_total">  <?php echo number_format($balamt,2);?></td>
    </tr>
    </table>
    <?php unset($dbh); unset($stmt); ?>
    <?php
    include '../templete/footer.php';
    ?>
4

1 回答 1

1

您必须检测列表上的日期何时更改。没有测试,但尝试这样的事情 -

<?php 
if(isset($stmt))
{ 
  $currdate = '';
  while($row = $stmt->fetch())
  {
    if($currdate != $row['SODate'] && $currdate != '') 
    {
      $currdate = $row['SODate'];
      ?>
      <tr>
        <td class="tbl_content_right" colspan="4">subtotal</td>
        <td class="tbl_content_right" colspan="2"><?php echo number_format($balamt,2) ;?></td>
      </tr>
      <?php
    }
    ?>
    <tr>
    <td class="tbl_content"><?php echo date("d-m-Y", strtotime($row['SODate']));?></td>
    <td class="tbl_content"><?php echo $row['MVCode'];?></td>
    <td class="tbl_content"><?php echo $row['MVName'];?></td>
    <td class="tbl_content_right"><?php echo number_format($row['Rate'],2) ;?></td>
    <td class="tbl_content_right"><?php echo number_format($row['Qty']) ;?></td>
    <td class="tbl_content_right"><?php echo number_format($row['BalAmt'],2) ;?></td>
    </tr>
    <?php 
    $balamt+=$row['BalAmt'];
    $qty+=$row['Qty'];
  }
}
?> 
于 2013-05-20T10:41:12.877 回答