Alternatively, this would add all missing zone entries in the `grid` table so the code doesn't crash looking up the max(id) for them:
Code:
INSERT INTO `grid`
SELECT DISTINCT 0, `zoneidnumber`, 0, 0 FROM `zone` WHERE `zoneidnumber` NOT IN
(SELECT DISTINCT `zoneid` FROM `grid`);