My explaination is what you are seeing, but remote2 is also correct. $result is a mysql query result index, not the number of rows returned. So you have two bugs in the posted code.
$result is an integer, but its value has no meaning except as a mysql query result. PHP internally maintains an array of mysql query result structures, and $result is just a value that is used as an index into that array, and has no meaning outside of that context.
To get the number of rows returned, use mysql_num_rows($result).