2015-05-15 18 views
4
中顯示的值總數

我正在使用預先定義的php庫存管理器。 所以在銷售我的數據是越來越這種方式存儲:PHP - 獲取表

[{"product_id":"8","total_number":"70","selling_price":"110"}] 

enter image description here

要顯示在表中我用下面的代碼,這些值

$sub_total   = 0; 
$invoice_entries = json_decode($row['invoice_entries']); 
foreach ($invoice_entries as $row2): 
    $sub_total += ($row2->total_number * $row2->selling_price);          
endforeach; 

$sub_total  = $sub_total - ($sub_total * ($row['discount_percentage']/100)); 
$grand_total = $sub_total + ($sub_total * ($row['vat_percentage']/100)); 
echo $grand_total; 

我這裏得到需要的結果是銷售總額。

enter image description here

現在,我想給的報告功能,它會顯示所有與客戶名稱,銷售價值的發票。 我想計算所有發票的總數,並在表格行中顯示,即總計爲$grand_total

我無法理解我該如何得到它。任何Java腳本可以做到這一點?我不明白js。所以我不知道它是否可能。

在此先感謝

+0

使用不同的庫存管理器 – Strawberry

+0

@Strawberry:良好的建議,但現在不適用,因爲客戶已經開始使用它:) – user1299086

+0

創建一個變量,簡單地命名爲'$ final_total',當重載頁面時,初始值爲0,'$ final_total + = $ grand_total'在每行獲得$ grand_total值,然後顯示它 –

回答

3

因爲你存儲數據庫中的數據,可以用另一個查詢到所有你想要檢索記錄總結所有的grand_total。

select sum(grand_total) from yourTable where yourFilter

如果grand_total是總結從另一個查詢,你可以使用嵌套查詢語句來完成它。

http://www.mysqltutorial.org/mysql-subquery/

這個環節對嵌套選擇一些示例。