繁体   English   中英

用html将php页面中的数据分组

[英]grouping data in php pages with html

我使用以下代码创建了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     

如果我将日期范围从2011年1月15日至2011年1月16日,则它在php页面中的显示如上。 但是,如果我将日期范围选择为2011年1月15日至2011年1月16日,则需要如下所示

请帮助我

 # 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';
    ?>

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

<?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'];
  }
}
?> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM