-
Notifications
You must be signed in to change notification settings - Fork 0
/
getworkingtypes.php
executable file
·52 lines (46 loc) · 1.32 KB
/
getworkingtypes.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()) {
$typeid=$row['device_type_id'];
$working=$row['device_working'];
if ($working) {
$faultstats[$typeid]['working']++;
} else {
$faultstats[$typeid]['faulty']++;
}
}
}
foreach ($faultstats as $key => $faultstat) {
$sql = "SELECT * FROM device_types WHERE device_type_id='$key'";
$result = $conn->query($sql);
$row = $result->fetch_assoc();
$typename=$row['device_type_name'];
$working=$faultstat['working'];
if (empty($working)) {
$working=0;
}
$faulty=$faultstat['faulty'];
if (empty($faulty)) {
$faulty=0;
}
$allfaultstats[$key]['name']=$typename;
$allfaultstats[$key]['working']=$working;
$allfaultstats[$key]['faulty']=$faulty;
$charti['value']=$working;
$charti['color']="Green";
$charti['highlight']="Green";
$charti['label']=$typename;
$charts[]=$charti;
// echo "<p>$key";
// print_r($faultstat);
}
//$smarty->assign("faultstats", $faultstats);
//print_r($faultstats);
//print_r($charts);
echo json_encode($charts);
die();