-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcharts.php
50 lines (37 loc) · 1.28 KB
/
charts.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
<?php
// Verbindung zum Datenbankserver
$pdo = new PDO('mysql:host=127.0.0.1;dbname=d0284a05', 'd0284a05', 'fvRdwCF4VeKkbdnp');
if (empty($_GET)){
// the date and time before 48 minutes
$date1 = date('Y-m-d H');
$date2 = date('Y-m-d H', time()-2880);
// get the exact time till which the results shall be shwon (exactly 48minutes before "now")
$date3 = date('Y-m-d H:i:s', time()-2880);
$statement = $pdo->prepare("SELECT * FROM bienenpi2_temp WHERE time LIKE :time1 OR time LIKE :time2");
$statement->execute(array('time1' => "%$date1%", 'time2' => "%$date2%"));
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
$data = array();
foreach($result as $row){
if($row['time']>$date3)
{
$data[] = $row;
}
}
}
else{
//echo "date: ", $_GET["date"];
$date = $_GET["date"];
$statement = $pdo->prepare("SELECT * FROM bienenpi2_temp WHERE time LIKE :time1");
$statement->execute(array('time1' => "%$date%"));
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
$data = array();
foreach($result as $row){
$data[] = $row;
}
}
// $data = json_encode($data1,JSON_NUMERIC_CHECK);
// print $data;
// $main = array('data'=>array($data));
// $data = $main;
print json_encode($data, JSON_NUMERIC_CHECK|JSON_PRETTY_PRINT);
?>