echo "<th>Control unit id</th>"; echo "<th>Machine and mode"; echo "<th>Status"; echo "<th>Queue"; echo "<th>Last finished task"; echo "</thead>"; $qUnits = mysql_query("SELECT * FROM control_unit"); while ($unit = mysql_fetch_object($qUnits)) { echo "<tr><td>" . $unit->id; $qTasks = mysql_query("SELECT * FROM control_tasks WHERE control_unit_id =" . $unit->id) or die(mysql_error()); if (mysql_num_rows($qTasks) == 0) { echo "<td>/"; } else { echo "<td>"; while ($task = mysql_fetch_object($qTasks)) { $machine = Machine::FromId($task->machine_id); $mode = Mode::FromId($task->mode_id); echo $machine->description(); echo $mode ? " with " . $mode->name() : ""; echo "<br>"; } } $queue = new TaskQueue($unit->id); echo "<td>"; if ($queue->has_active_task()) { $active = $queue->get_active_task(); echo "running"; echo "<span title='" . date("G:i d/m/Y", $active->start_time()) . "'> started " . time_ago($active->start_time()) . " ago</span>"; } else { echo "not running"; }