-
Notifications
You must be signed in to change notification settings - Fork 1
/
sum_of_columns_year.php
46 lines (35 loc) · 1.35 KB
/
sum_of_columns_year.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
include('connect_DB.php');
$sum_year=array();
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE,PDO::FETCH_OBJ);
for ($i=0; $i < 6; $i++) {
$column_name="0".strval($i);
$query="SELECT SUM(COALESCE(`".$column_name."`,0.00)) AS column_sum FROM vuosi";
//$query='SELECT SUM(COALESCE(`'.$column_name.'`,0.00)) AS column_sum FROM kuukausi_0';
$stmt=$pdo->prepare($query);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$sum_year[$i] = $row['column_sum'];
// echo $sum_year[$i];
// echo "<br>";
}
$sum_year_B=array();
$menotyyppi=array("tulot","asuminen","nordea","sahko","vakuutukset");
$menotyyppi_sum=array();
for ($i=0; $i < 5 ; $i++) {
# code...
$query="SELECT SUM(COALESCE(`".$menotyyppi[$i]. "`,0.00)) AS " .$menotyyppi[$i] ."_sum FROM vuosi";
//$query='SELECT SUM(COALESCE(`'.$column_name.'`,0.00)) AS column_sum FROM kuukausi_0';
$stmt=$pdo->prepare($query);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$apu_String=$menotyyppi[$i]."_sum";
$sum_year_B[$i] = $row[$apu_String];
}
$query="SELECT SUM(COALESCE(`tulot`,0.00)) AS tulot_sum FROM vuosi";
//$query='SELECT SUM(COALESCE(`'.$column_name.'`,0.00)) AS column_sum FROM kuukausi_0';
$stmt=$pdo->prepare($query);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$sum_year['tulot'] = $row['tulot_sum'];
$pdo = null;