I'm guessing you're missing a loop (and you may want
to work on indenting ;-) but:
$count = ++$count;
isn't, probably, what you mean; it increments count and
assigns it to count but, of course, when is undeterministic.
That's a different problem, but
$count++;
is probably enough. Still, you seem to be 'while fetchrow'
through one loop and stepping through array at the same time.
Did you mean to loop through array for each row?
a