-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_data17.php
72 lines (66 loc) · 2.24 KB
/
get_data17.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
<?php
$table = "t_update";
include '../conn.php';
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
if($page == 0){$page = 1;}
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$offset = ($page-1)*$rows;
try{
$sth = $dbh->prepare("select count(DISTINCT timestamp) from $table
where date_format( timestamp, '%i' ) % 10 = 0
and dev_switch = '1' ");
$sth->execute();
$row = $sth->fetch(PDO::FETCH_ASSOC);
$result = array();
$result['total'] = $row['count(DISTINCT timestamp)'];
$sth = $dbh->prepare("select concat( date_format( timestamp, '%Y-%m-%d %H:' ), floor( date_format( timestamp, '%i' ) /10 ) ) as time_period,
sum(dev_switch) as nums
from $table
where dev_switch = '1'
group by time_period
limit $offset,$rows");
$sth->execute();
$items = array();
while($row = $sth->fetch(PDO::FETCH_ASSOC)){
array_push($items, $row);
}
$result['rows'] = $items;
}catch(PDOException $e){
$result = array();
$result['isError'] = $e->getMessage();
echo json_encode($result);
exit;
}
<?php
$table = "t_update";
include '../conn.php';
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
if($page == 0){$page = 1;}
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$offset = ($page-1)*$rows;
try{
$sth = $dbh->prepare("select count(DISTINCT timestamp) from $table
where date_format( timestamp, '%i' ) % 10 = 0
and dev_switch = '1' ");
$sth->execute();
$row = $sth->fetch(PDO::FETCH_ASSOC);
$result = array();
$result['total'] = $row['count(DISTINCT timestamp)'];
$sth = $dbh->prepare("select concat( date_format( timestamp, '%Y-%m-%d %H:' ), floor( date_format( timestamp, '%i' ) /10 ) ) as time_period,
sum(dev_switch) as nums
from $table
where dev_switch = '1'
group by time_period
limit $offset,$rows");
$sth->execute();
$items = array();
while($row = $sth->fetch(PDO::FETCH_ASSOC)){
array_push($items, $row);
}
$result['rows'] = $items;
}catch(PDOException $e){
$result = array();
$result['isError'] = $e->getMessage();
echo json_encode($result);
exit;
}