This repository was archived by the owner on Aug 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetData.php
75 lines (57 loc) · 1.82 KB
/
getData.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
<?php
// {
// "cols": [
// {"id":"","label":"Any","pattern":"","type":"string"},
// {"id":"","label":"Temperatura","pattern":"","type":"number"}
// ],
// "rows": [
// {"c":[{"v":"23/12/1957","f":null},{"v":24,"f":null}]},
// {"c":[{"v":"23/12/1957","f":null},{"v":21,"f":null}]},
// {"c":[{"v":"23/12/1957","f":null},{"v":21,"f":null}]},
// {"c":[{"v":"23/12/1957","f":null},{"v":22,"f":null}]},
// {"c":[{"v":"23/12/1957","f":null},{"v":20,"f":null}]}
// ]
// }
include("connect.php");
$mysqli = new mysqli($server, $user, $pass, $db);
if ($mysqli->connect_errno)
{
echo "Error: Fallo al conectarse a MySQL debido a: \n";
echo "Errno: " . $mysqli->connect_errno . "\n";
echo "Error: " . $mysqli->connect_error . "\n";
exit;
}
$myObj = (object)array();
$myObj->cols = array(
array("id" => "", "label" => "Any", "pattern" => "", "type" => "string"),
array("id" => "", "label" => "Temperatura", "pattern" => "", "type" => "number")
);
$myObj->rows = array();
$sql = "SELECT * FROM (SELECT data, temp FROM temp1_data ORDER BY 1 DESC LIMIT 2000) AS a ORDER BY 1 ASC";
$result = $mysqli->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$temp = array("c" => array(
array("v" => $row["data"], "f" => null),
array("v" => $row["temp"], "f" => null)
)
);
array_push($myObj->rows, $temp);
}
} else {
echo "0 results";
}
$mysqli->close();
// Model JSON Data
// $temp = array("c" => array(
// array("v" => "2018-01-01", "f" => null),
// array("v" => 22, "f" => null)
// )
// );
// array_push($myObj->rows, $temp);
// array_push($myObj->rows, $temp);
// array_push($myObj->rows, $temp);
$myJSON = json_encode($myObj);
echo $myJSON;
?>