No good reason that I can think of but I haven't dug into the details of your code. In your opening post you said you didn't get data. Now you do? I am not aware of any particular reason the while loop wouldn't run. SO... troubleshooting time.
What happens if you remove the while statement and simply try to output the number of rows returned or the data from a single row?