I have got the $%£%"%^$ thing up and running again, with caveats...
As is the way with these things, once I'd broken it (at around 11:30 last night) I noticed one or two other things:
I never planned (initially) on actually putting this live on the web, so I didn't consider that more than one person might be accessing the page at the same time. I'm pretty sure there's a straightforward solution to this in that I can assign a username to each person's week pattern and timetable then build the final query to only include their data (at present the tables are emptied before new data is added).
At one stage in the development I had it set up so the first day in the year became the Monday before the date selected (if it wasn't already a Monday). This makes the date pattern display properly with accurate "Week Commencing" dates. At some point I've lost that code (and forgotten how to do it!).
None of these 3 bugs prevent it from working completely, so I've left the site live at present with a warning at the top. Feel free to pass it on (to Firefox users!) - the worst that can happen is that they waste 5 minutes because someone else is using it at the same time.