Your problem with the footer appearing in the middle of the table appears to be that your are not opening and closing your table cells correctly. If you design allows it, you should make a header table and a footer table. This will make things a lot easier as you can include the header and footer from remote files.
How to include files:
<? include_once("footer.html"); ?>