First of all, you should fix the php errors, coming from the script.If the scripts are good written, then your mysql server or your server database is down.That cause the page to exceed the limits and that's why you're missing some parts of images.
Secondly, in order for this to work properly, even if the mysql db is down, is to put some die() messages, or just put a "@" before each query on mysql.
Hope I helped a bit,
-Blane