well from what i can tell it seem that you might be talking about this while loop.
while (1) {
right? well, the problem with that is your don't have a condition of when that loop will stop. you are basically saying...
while(ALWAYS TRUE) continue..... this will NEVER stop.
on top of this you have 3 nested while loops. I'm not sure if that is really necessary. i think you just need 2.
this is what i would do.
remove the outer while loop. the one that goes:
While(!Connection_Aborted()) {
then change this:
while (1) {
to something like this: (just an example)
$end = mysql_num_rows($query);
$count = 1;
while($count < $end){
... you code
$count++;
}
hope that help or gives you an idea.