query('SELECT * FROM system WHERE x IS NULL OR y IS NULL OR z IS NULL'); $update = $pdo->prepare('UPDATE system SET x = :x, y = :y, z = :z WHERE id = :id'); $systems = $query->fetchAll(PDO::FETCH_ASSOC); foreach ($systems as $system) { $data = file_get_contents("https://www.edsm.net/api-v1/system?systemName=" . urlencode($system['name']) . "&coords=1"); if($data === "[]"){ continue; } $data = json_decode($data); $update->execute(array( ':x' => $data->coords->x, ':y' => $data->coords->y, ':z' => $data->coords->z, ':id' => $system['id'], )); sleep(1); }