query( 'SELECT machines.id as machine, IIF("values".value = 1, MIN(states.id), MAX(states.id)) as minax_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, "values".value' ); $stm = $db -> prepare( 'SELECT machines.name as machine, datetime(machines.last_update, "localtime") AS 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' . ' WHERE machines.id = :machine' . ' AND states.id = :state' ); $values = array(); while ($row = $result -> fetchArray()) { $stm -> bindValue('machine', $row['machine']); $stm -> bindValue('state', $row['minax_state']); $stmres = $stm -> execute(); $stmres = $stmres -> fetchArray(); $values[$row['machine']][$stmres['value']] = $stmres; $values[$row['machine']]['any'] = $stmres; } $stm -> close(); ?> ' . $text . ''; } foreach ($values as $value) { if (array_key_exists('0', $value)) $color = '#800000'; else $color = '#008000'; ?>
machine state last update