summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2022-07-20 13:34:04 +0200
committerErich Eckner <git@eckner.net>2022-07-20 13:34:04 +0200
commitfc333f6f06b47678750af15f9568657b2fa3f2a1 (patch)
treebdc5a4d5799edc9f9517af4e5a03bdd6639b36b7
parent8de8c576da92f6943e7ab5339b6286d3162b48d9 (diff)
downloadcolocation-fc333f6f06b47678750af15f9568657b2fa3f2a1.tar.xz
index.php: fetch correct values
-rw-r--r--html/index.php34
1 files changed, 24 insertions, 10 deletions
diff --git a/html/index.php b/html/index.php
index 38f4f3d..776694b 100644
--- a/html/index.php
+++ b/html/index.php
@@ -11,14 +11,23 @@ $result = $db -> query(
' 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' .
+$stm = $db -> prepare(
+ 'SELECT machines.name as machine, states.name as state, "values".value' .
' FROM machines' .
- ' JOIN "values" ON machines.id = "values".machine_id' .
+ ' JOIN "values" ON "values".machine_id = machines.id' .
' JOIN states ON "values".state_id = states.id' .
- ' GROUP BY machines.id'
+ ' WHERE machines.id = :machine' .
+ ' AND states.id = :state'
);
+$values = array();
+
+while ($row = $result -> fetchArray()) {
+ $stm -> bindValue('machine', $row['machine']);
+ $stm -> bindValue('state', $row['min_state']);
+ $stmres = $stm -> execute();
+ $values[$row['machine']] = $stmres -> fetchArray();
+}
+$stm -> close();
?>
<html><body><table>
@@ -29,11 +38,16 @@ $result = $db -> query(
</tr>
<?php
-while ($row = $result -> fetchArray()) {
-?>
-<tr>
- <td><?php echo $row['machine']; ?></td>
- <td><?php echo $row['state']; ?></td>
+foreach ($values as $value) {
+?> <tr>
+ <td><?php echo $value['machine']; ?></td>
+ <td><?php
+
+if ($value['value'] != 1)
+ echo 'not ';
+echo $value['state'];
+
+?></td>
<td><?php echo $row['last_update']; ?></td>
</tr>
<?php