-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheconomy.php
67 lines (60 loc) · 1.58 KB
/
economy.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
<title>营收额统计</title>
<h1>营收额统计</h1>
<?php
session_start();
// 连接数据库
$link = mysqli_connect('localhost:3308', 'root', '', 'bigwork');
if (!$link) {
echo '数据库连接失败<br>';
exit();
}
?>
<h3>今年统计图表</h3>
<?php
// 遍历已支付订单,统计每月金额
$total = array(0,0,0,0,0,0,0,0,0,0,0,0); // 注意1月的下标是0
$sql = "select * from login";
$result = mysqli_query($link, $sql);
if (!$result) {
echo '执行失败'.mysqli_error($link);
}
$result = $result->fetch_all();
for ($i = 0; $i < count($result); $i++) {
// 分离出月份
$temp = explode('-', $result[$i][3]);
$month = $temp[1];
// 在对应月份上加上金额
$total[(int)$month - 1] += (int)$result[$i][6];
}
// 绘图
$_SESSION['graph_data'] = $total;
echo '<img src="graph.php" alt="折线图">';
?>
<h3>账单详细一览</h3>
<table border="1">
<tr>
<th>订单号</th>
<th>结账时间</th>
<th>应结金额</th>
<th>实际结算金额</th>
</tr>
<?php
// 遍历已支付的订单
$sql = "select * from login";
$result = mysqli_query($link, $sql);
if (!$result) {
echo '执行失败'.mysqli_error($link);
}
$result = $result->fetch_all();
for ($i = 0; $i < count($result); $i++) {
echo <<<xxx
<tr>
<th>{$result[$i][0]}</th>
<th>{$result[$i][3]}</th>
<th>{$result[$i][5]}</th>
<th>{$result[$i][6]}</th>
</tr>
xxx;
}
?>
</table>