Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

grouping the data and their total in php page

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

grouping the data and their total in php page

Postby maideen » Fri May 17, 2013 8:22 pm

Hi
I have generated the Php page with sales data with total of sales and work fine. But In same page I need the sales by group like product-1 My html code is available in below

Currently I have generated like what is below. But I need to calculate by group (based on ID)

ID Date Price Qty
0001 20130105 2.70 5 13.50
0002 20130105 2.70 9 24.30
0003 20130106 2.70 6 16.20
0002 20130106 2.70 7 18.90
0001 20130107 2.70 5 13.50
0002 20130107 2.70 9 24.30
0003 20130109 2.70 6 16.20
0002 20130108 2.70 7 18.90
145.80
I need the below format
Example

ID Date Price Qty
0001 20130105 2.70 5 13.50
0001 20130107 2.70 5 13.50
Sub Total 27.20

0002 20130105 2.70 9 24.30
0002 20130106 2.70 7 18.90
0002 20130108 2.70 7 18.90
0002 20130107 2.70 9 24.30
Sub Total 86.40

0003 20130109 2.70 6 16.20
0003 20130106 2.70 6 16.20
Sub Total 32.40

Grand total 145.80

B\
Code: Select all
       <?php
          if(isset($stmt))
            {
                while($row = $stmt->fetch())
            {?>
    <tr>
      <td class="tbl_content"><?php echo $row['Code'];?></td>
      <td class="tbl_content"><?php echo $row['Name'];?></td>
      <td class="tbl_content"><?php echo $row['SONo'];?></td>
      <td class="tbl_content"><?php echo date("d-m-Y", strtotime($row['SODate']));?></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['RTNQty']) ;?></td>
      <td class="tbl_content_right"><?php echo number_format($row['BalQty']) ;?></td>
      <td class="tbl_content_right"><?php echo number_format($row['BalAmt'],2) ;?></td>
 
    </tr>
   
    <?php
        $balamt+=$row['BalAmt'];
        $balqty+=$row['BalQty'];
        $rtnqty+=$row['RTNQty'];
        $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>



pls hel me

thanks


Maideen
maideen
New php-forum User
New php-forum User
 
Posts: 27
Joined: Mon Mar 07, 2011 11:38 pm

Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron