$idresult = $conn->query("SELECT id FROM pictures"); while ($row = $idresult->fetch_assoc()){ mysqli_query($conn, "UPDATE pictures SET UniqueKey = '$UniqueKey' WHERE id = " . $row['id']); }