George, let me advise you on something. Beeing a programmer is not only about writing a code, but also about orgnizing it. To me your problem seem just like it has something to do with organizing it. Think of organizing a site this way:
you have one script that does it all - if it is a small site, or you have also one script that calls every other if there are too many of them.
So try to do things cetralized: have one script. I know I didn't post you any code here but I am 100% certain this advice helps.
If you don't have time to reorganize your site (your boss is peace of @!#$) then solve your problem dirty and go on approaching things differently.
I learned on college that it is the organization of the code that make good programmar good, fast, and he also lives longer.
Bye!