I have a table which holds a list of IDs, and various other columns such as IDName.
The Primary Key of the table is the ID itself, however it does not auto_increment
Unless your application is in very high demand the number of collisions will be very low. So I would simply retry if a key error is raised.
select coalesce(max(id), 27770000) + 1 from myTable where id / 10000 = 2777
The coalesce is there in case that level/code does not yet exist.