You need to output the headers before going into the loop, so they only get printed once.