-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
87 lines (55 loc) · 1.7 KB
/
functions.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
include_once('connect.php');
function getCurrentBalance(){
$result = mysql_query("SELECT * FROM current_amount");
$sum= 0;
while ($row = mysql_fetch_assoc($result)) {
$value=$row['current_amount'];
$sum += $value;
}
return $sum;
}
function getAllValues(){
$result = mysql_query("SELECT * FROM current_amount ORDER BY id DESC");
while ($row = mysql_fetch_assoc($result)) {
echo '<div class="float_left">', $row['current_amount'],'
<button class="',$row["id"],'">Delete</delete></div>';
}
}
function getLastTransaction(){
$result = mysql_query("SELECT * FROM current_amount ORDER BY id DESC LIMIT 1");
while ($row = mysql_fetch_assoc($result)) {
echo $row['current_amount'];
}
}
function addAmount($amount){
if(mysql_query("INSERT INTO current_amount (current_amount) VALUES('$amount')")){
$id_query = mysql_query("SELECT * FROM current_amount ORDER BY id DESC LIMIT 1");
while ($row = mysql_fetch_assoc($id_query)) {
$lastTransaction=$row['current_amount'];
$id= $row['id'];
}
$current_balance=getCurrentBalance();
echo '{"id": "',$id,'", "lastTransaction":"'
,$lastTransaction,'","current_amount":"',$current_balance,'"}';
}
else
echo "fail";
}
function subtractAmount($amount){
$amount= -$amount;
if(mysql_query("INSERT INTO current_amount (current_amount) VALUES('$amount')")){
$amount=getLastTransaction();
return $amount;
}
else
echo "fail";
}
function deleteTransaction($transactionToDelete){
if(mysql_query("DELETE FROM current_amount WHERE id=".$transactionToDelete)){
echo $transactionToDelete;
}
else
echo "failll";
}
?>