Here's a few tips I think you'll find usefull.
If not, use them anyway because I say so :-)
1) Never quote vars unless you are printing them along with other strings
good: echo "this is my $var";
good: $a=$b;
bad: $a="$b";
2) Don't copy all the mysql results into arrays unless you absolutely have to
(and you hardly ever have to)
3) if you are going to copy the data into an array, use the easy method:
while($row=mysql_fetch_array($result,MYSQL_ASSOC))
{
$array[]=$row;
}
Now $array is an array of rows, and you can access it like this:
echo $array[$row_number]['field_name'];
4) but, in the example you posted you don't need to put everything into an array, you can just print it as they come out of the mysql query.
That saves time and memory
5) allways initialize your array's before you use them.
In your example, you are assuming that PHP will create a new empty array at the point where you first put a value in. That's probably what PHP does, but you shouldn't trust that to happen. Instead, use $my_array=array(); before you start using $my_array, to make sure you are using a newly created, empty array.