-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiOSHumidity.php
49 lines (43 loc) · 1.08 KB
/
iOSHumidity.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
require_once("creds.php");
$mysqli = new mysqli("localhost", $dbUsername, $dbPassword, $dbName);
if (!$mysqli)
{
die('Connect Error ' . $conn->errno . ': ' . $conn->error);
}
else
{
//$deviceId = "2336c2eb6e4936ee";
//$date = date('Y-m-d');
$dateA = $_POST['date'];
$deviceIdA = $_POST['deviceId'];
$result = $mysqli->query("SELECT DATE_FORMAT(timeInfo,'%r') as 'timeInfo', humidity FROM sensors WHERE DATE(timeInfo) = DATE('$dateA') AND impId='$deviceIdA'");
if ($result->num_rows > 0)
{
//echo '{"success":1}';
$full = '{"success":1,"data":[';
$inc = 1;
while($resultSet = $result->fetch_assoc()){
$str1 = '{"time": "';
$str2 = $resultSet['timeInfo'];
$str3 = '","humidity":';
$str4 = $resultSet['humidity'];
$str5 = '}';
$full = $full.$str1.$str2.$str3.$str4.$str5;
if ($inc < $result->num_rows) {
//add comma to result
$full= $full.",";
}
$inc++;
}
$end = ']}';
$full = $full.$end;
echo $full;
//echo implode("<br/>",$time);
$result->close();
}
else
{
echo '{"success":0}';
}
}