summaryrefslogtreecommitdiff
path: root/html/index.php
blob: 38f4f3d84468f433371167e7c74e3d23df96ca2b (plain)
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
<?php

include "db.php";

$result = $db -> query(
  'SELECT machines.id as machine, MIN(states.id) as min_state' .
  ' FROM machines' .
  ' JOIN "values" ON machines.id = "values".machine_id' .
  ' JOIN states ON "values".state_id = states.id' .
  ' WHERE "values".value IS NOT NULL' .
  ' GROUP BY machines.id'
);

$result = $db -> query(
//  'SELECT machines.name as machine, GROUP_CONCAT(states.name || \': \' || "values".value, \',\') as state, last_update' .
  'SELECT machines.name as machine, GROUP_CONCAT(states.name || \': \' || IFNULL("values".value, \'NULL\'), \',\') as state, machines.last_update' .
  ' FROM machines' .
  ' JOIN "values" ON machines.id = "values".machine_id' .
  ' JOIN states ON "values".state_id = states.id' .
  ' GROUP BY machines.id'
);

?>
<html><body><table>
<tr>
  <th>machine</th>
  <th>state</th>
  <th>last update</th>
</tr>
<?php

while ($row = $result -> fetchArray()) {
?>
<tr>
  <td><?php echo $row['machine']; ?></td>
  <td><?php echo $row['state']; ?></td>
  <td><?php echo $row['last_update']; ?></td>
</tr>
<?php
}
?>
</table></body></html>