Aha. Thanks, but I figured out an easy way to do it. I just used an if statement asking if the column at $i was existant or not. If so, execute the code; if not, break the for loop.
But here's another question... how do you delete columns from a table?