我有一個數據庫用於跟蹤項目權重。 的領域是: ID,電子郵件,order01,order02,order03,ORDER_TOTAL總結行並插入新列
示例數據:
1 [email protected] 0.250 0.000 0.000 0.000
2 [email protected] 0.510 1.888 0.219 0.000
3 [email protected] 0.219 0.500 0.000 0.000
4 [email protected] 0.219 0.000 0.000 0.000
我能夠添加數據(即新行或更新現有行) 我也是能夠使用php在html表格中顯示數據 我也可以對每行進行求和並且通過電子郵件分出一個列。 我需要做的是對每一行進行求和,並在最後一個不同的列中插入總和。需要
示例數據:
1 [email protected] 0.250 0.000 0.000 0.250
2 [email protected] 0.510 1.888 0.219 2.617
3 [email protected] 0.219 0.500 0.000 0.719
4 [email protected] 0.219 0.000 0.000 0.219
同樣,我能夠在一個表中顯示的數據,我能總結每一行 - 我似乎無法弄清楚如何獲得插入適當的立柱
這總和是我使用的彙總數據代碼:
$result = mysql_query('SELECT email, (order01+order02+order03) AS order_total FROM `customer_orders`');
if (mysql_num_rows($result) > 0) {
print '<ul>';
$sum = array(); // initialize
while ($myrow = mysql_fetch_array($result)) {
$sum[] = $myrow['order_total']; // sum
$ordertotal= $myrow['order_total'];
print "<li>$ordertotal</li>";
}
$sum = array_sum($sum);
print "</ul>$sum\n";
} else {
print "<h1>No results</h1>\n";
}
這將會給我一個網頁,一列看起來像這樣:
0.250
2.617
0.719
0.219
3.8
我並不真正關心每一列的總數,或總計......只是每行的總和,加到相應的行上。