-
Notifications
You must be signed in to change notification settings - Fork 0
/
getfaultyrooms.php
executable file
·52 lines (46 loc) · 1.28 KB
/
getfaultyrooms.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
<?php
require_once('config.php');
require_once('loginneeded.php');
$sql = "SELECT * FROM devices";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$roomid=$row['roomid'];
$working=$row['device_working'];
if ($working) {
$faultstats[$roomid]['working']++;
} else {
$faultstats[$roomid]['faulty']++;
}
}
}
foreach ($faultstats as $key => $faultstat) {
$sql = "SELECT * FROM rooms WHERE roomid='$key'";
$result = $conn->query($sql);
$row = $result->fetch_assoc();
$roomname=$row['roomname'];
$working=$faultstat['working'];
if (empty($working)) {
$working=0;
}
$faulty=$faultstat['faulty'];
if (empty($faulty)) {
$faulty=0;
}
$allfaultstats[$key]['name']=$roomname;
$allfaultstats[$key]['working']=$working;
$allfaultstats[$key]['faulty']=$faulty;
$charti['value']=$faulty;
$charti['color']="Red";
$charti['highlight']="Red";
$charti['label']=$roomname;
$charts[]=$charti;
// echo "<p>$key";
// print_r($faultstat);
}
//$smarty->assign("faultstats", $faultstats);
//print_r($faultstats);
//print_r($charts);
echo json_encode($charts);
die();