UNIX_TIMESTAMP()-300 GROUP BY `z`.`device`;"; $result = mysql_run($query, $db_main_handle); while ($tmp = mysql_fetch_assoc($result)) $data[$tmp['id']] = $tmp; // Fetch all active products in last 30 min $query = "SELECT `z`.`device` as `id`, `d`.`naam` as `name`, COUNT(distinct `z`.`id`) as `online30` FROM `zkl_cache` `rt`, `zkl` `z`, `device_name` `d` WHERE `d`.`i18n`='nl' AND `d`.`device`=`z`.`device` AND `z`.`id`=`rt`.`zkl` AND `rt`.`t` > UNIX_TIMESTAMP()-1800 GROUP BY `z`.`device`;"; $result = mysql_run($query, $db_main_handle); while ($tmp = mysql_fetch_assoc($result)) { if (!isset($data[$tmp['id']])) $data[$tmp['id']] = $tmp; $data[$tmp['id']]['online30'] = $tmp['online30']; } echo json_encode($data); ?>