#!/usr/bin/php connect()) { logdie($myLog, 'ERROR Database connect error (1)'); } $res = $db->customQuery('select server,count(server) as count from queue group by server'); if ($res) { $r = $res->fetchAll(PDO::FETCH_ASSOC); } else { logdie($myLog, 'ERROR getting data from db'); } foreach ($shortnames as $shortname) { $count = 0; foreach ($r as $result) { if(strpos($result['server'], "$shortname.") !== FALSE) { $count = $result['count']; break; } } echo "queuelength_${shortname}.value $count\n"; }