2016-09-17 64 views
0

我想在每行的末尾顯示每行的總值...所有記錄都從數據庫中獲取,但如何計算每行的總數價值和如何在每一行的結尾顯示它?請幫忙。需要每行的總值,並應該顯示在行的末尾

<table class="rwd-table ui form" id="myTable"> 
 
     
 
    
 
<thead> 
 
    <tr> 
 
    <th width="50%">DATE</th> 
 
    <th>TARGET DAILY CONSUMPTION MMBTU</th> 
 
    <th>CONSUMPTION FROM 00H TO 12H IN MMSCF</th> 
 
    <th>CONSUMPTION FROM 12H TO 24H IN MMSCF</th> 
 
    <th>CONSUMPTION PER RAK GAS IN MMBTU</th> 
 
    <th>REASON OF VARIATION OF CONSUMPTION BETWEEN ACTUAL & TARGET</th> 
 
    </tr> 
 
</thead> 
 
<tbody> 
 
    <?php foreach ($view as $report) {?> 
 
    <tr style="color: #000000;"> 
 
    <td><?php echo $report['date'];?></td> 
 
    <td><?php echo $report['Target Daily Consumption in MMBTU'];?></td> 
 
    <td><?php echo $report['Consumption From 00h to 12h in MMSCF'];?></td> 
 
    <td><?php echo $report['Consumption From 12h to 24h in MMSCF'];?></td> 
 
    <td><?php echo $report['Consumption As Per RAK Gas in MMBTU'];?></td> 
 
    <td><?php echo $report['Reason of Variation of Consumption Between ACTUAL & TARGET'];?></td> 
 
    </tr> 
 
    <?php }?> 
 
    </tbody> 
 
</table>

+0

實際結果是'​​'裏面的內容,需要添加 – Samir

+0

什麼是總價值在這裏以及如何得到它? – Kafo

+0

你有所有的選擇打開,在'DOMConentLoaded'之後使用'PHP'或使用'JavaScript'來使用 – Rayon

回答

1

你可以簡單地像在循環之前加一個變量:

$tot = 0; 

再經過sum_total鈣添加:

$tot += $sum_total; 

我也做對sum_total進行一些更改(如果使用整數):

$sum_total = intval($row['stock_count']) * intval($row['stock_price']); 

或者(如果你用浮漂工作):

$sum_total = floatval($row['stock_count']) * floatval($row['stock_price']); 

而且具有:

​​

可以打印浮球2位小數。