Hmmm, I don't think your method is the best Mr Dooby.
I agree with Mr Tech's method. It will be easier to manage (phpadsnew is an excellent free script if you don't want to code your own) and will load fast.
phpadsnew doesn't only use PHP to display its results. You can use JavaScript, iframes and a few other methods which are good for templated scripts such as a vBulletin forum
Good luck.