To correctly list your IDs from the MySQL result, iterate through the result set using fetch_assoc() instead of a fixed range loop.
Use a loop to fetch each row from the result set and access the ID directly. Replace ‘$x’ with the ‘ID’ from the database.
Collection
[
|
...
]