-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.php
More file actions
67 lines (61 loc) · 1.62 KB
/
test.php
File metadata and controls
67 lines (61 loc) · 1.62 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<html>
<head>
</head>
<body>
<?php
//get session data
session_start();
$login_email = $_SESSION['email'];
if(!isset($_SESSION['email'])){
header("Location: /login.php");
exit();
}
include 'dbms.php';
$mileage_list = array();
$sql = "select expense.id,point,date,type,price from expense,mileage where expense.id = mileage.id and email='" . $login_email ."'";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()){
$point = $row['point'];
$date = getDate(strtotime($row['date']));
$type = $row['type'];
$price = $row['price'];
$data = array(
"point" => $point,
"date" => $date,
"type" => $type,
"price" => $price,
);
array_push($mileage_list,$data);
}
$mileage_sum_list = array();
$fixed_sum_list = array();
foreach($mileage_list as $data){
$date = $data["date"];
$key = $date['year'] . "-" . $date['mon'] ; #"0000-00"
if(!isset($sum_list[$key])){
$mileage_sum_list[$key] = intval($data["point"]);
}else{
$mileage_sum_list[$key] += $data["point"];
}
if(!strcmp($data['type'],"fixed")){
if(!isset($fixed_sum_list[$key])){
$fixed_sum_list[$key] = intval($data["price"]);
}else{
$fixed_sum_list[$key] += $data["price"];
}
}
}
$year = "2017";
$mileage_month_array = array();
$fixed_month_array = array();
for($i = 1; $i < 13; $i++){
$year_month_str = $year."-".$i;
$mileage_month_sum = $mileage_sum_list[$year_month_str];
$fixed_month_sum = $fixed_sum_list[$year_month_str];
array_push($mileage_month_array,$mileage_month_sum);
array_push($fixed_month_array,$fixed_month_sum);
}
echo var_dump($fixed_month_array);
?>
</body
</html>