diff options
author | Erich Eckner <git@eckner.net> | 2022-07-20 14:42:45 +0200 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2022-07-20 14:42:45 +0200 |
commit | 13bab0694648f419b76f728f0a5f3af0eea6659e (patch) | |
tree | 73734d62cf068a72bf5bec0a70fe4876193ddf9f | |
parent | a98d2bc96cf6c65532c8e1139ef4fc7124021965 (diff) | |
download | colocation-13bab0694648f419b76f728f0a5f3af0eea6659e.tar.xz |
index.php: show highest 0 and 1
-rw-r--r-- | html/index.php | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/html/index.php b/html/index.php index 2c15cde..8fb46da 100644 --- a/html/index.php +++ b/html/index.php @@ -8,11 +8,11 @@ $result = $db -> query( ' 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' + ' GROUP BY machines.id, "values".value' ); $stm = $db -> prepare( - 'SELECT machines.name as machine, states.name as state, "values".value' . + 'SELECT machines.name as machine, machines.last_update, states.name as state, "values".value' . ' FROM machines' . ' JOIN "values" ON "values".machine_id = machines.id' . ' JOIN states ON "values".state_id = states.id' . @@ -25,7 +25,9 @@ while ($row = $result -> fetchArray()) { $stm -> bindValue('machine', $row['machine']); $stm -> bindValue('state', $row['min_state']); $stmres = $stm -> execute(); - $values[$row['machine']] = $stmres -> fetchArray(); + $stmres = $stmres -> fetchArray(); + $values[$row['machine']][$stmres['value']] = $stmres; + $values[$row['machine']]['any'] = $stmres; } $stm -> close(); @@ -38,20 +40,29 @@ $stm -> close(); </tr> <?php -function print_colorized($value, $text) { - echo '<font color="'; - if ($value == 1) - echo '#008000'; - else - echo '#800000'; - echo '">' . $text . '</font>'; +function colorize($color, $text) { + return '<font color="' . $color . '">' . $text . '</font>'; } foreach ($values as $value) { + + if (array_key_exists('0', $value)) + $color = '#800000'; + else + $color = '#008000'; + ?> <tr> - <td><?php print_colorized($value['value'], $value['machine']); ?></td> - <td><?php print_colorized($value['value'], ($value['value'] == 1 ? '' : 'not ') . $value['state']); ?></td> - <td><?php print_colorized($value['value'], $row['last_update']); ?></td> + <td><?php echo colorize($color, $value['any']['machine']); ?></td> + <td><?php + +if (array_key_exists(0, $value)) + echo colorize('#800000', 'not ' . $value[0]['state'] . (array_key_exists(1, $value) ? ', ' : '')); + +if (array_key_exists(1, $value)) + echo colorize('#008000', (array_key_exists(0, $value) ? 'but ' : '') . $value[1]['state']); + +?></td> + <td><?php echo colorize($color, $value['any']['last_update']); ?></td> </tr> <?php } |