Can you post the function that your while loop is a part of within your functions file, or potentially even just your functions file (although that could be exceptionally long, so if you do that maybe use http://pastebin.com/
It could be something to do with how you’re calling in the function itself within functions instead of using that code within a template file.
Anything you can provide will give us some clues to help 🙂