You have an erroneous semicolon after the while
condition:
while($row2 = mysql_fetch_array($result2));
^ -- remove this
With this semicolon in place, you loop over an empty statement until your resultset is exhausted and then you execute the echo
statement contained within your braces (with $row2
now false) irrespective of the while
loop before.