$locations]); } $updates = array(); $nulls = array(); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { $loc = Location::mapIpToLocation($row['clientip']); if ($loc === false) { $nulls[] = $row['machineuuid']; } else { if (!isset($updates[$loc])) { $updates[$loc] = array(); } $updates[$loc][] = $row['machineuuid']; } } if (!empty($nulls)) { Database::exec("UPDATE machine SET subnetlocationid = NULL WHERE machineuuid IN (:nulls)", ['nulls' => $nulls]); } foreach ($updates as $lid => $machines) { if (empty($machines)) continue; Database::exec("UPDATE machine SET subnetlocationid = :lid WHERE machineuuid IN (:machines)", ['lid' => $lid, 'machines' => $machines]); } } }