if($_GET['type']){$where="AND type = '$_GET[type]'";}
$sql="select * from devices AS D, device_uptime AS U WHERE D.id = U.device_id $where ORDER BY `ignore`, `status`, `os`, `hostname`";
if($_GET['status']=="alerted"){$sql="select *, D.id as id from devices AS D, device_uptime AS U WHERE D.id = U.device_id ".str_replace("WHERE","OR",$device_alert_sql)." GROUP BY `id` ORDER BY `ignore`, `status`, `os`, `hostname`";}