There's an important thing missing here, making it a quite-unsafe way to program:
$result = mysql_query(blah blah blah blah);
$numrows = mysql_num_rows($result);
What happens if the query fails? $result is not a valid mysql result ID in that case, and so you'll just get an error messages when you try to retrieve the number of rows. Instead, you need to do this:
$sql = "blah blah blah";
$result = mysql_query( $sql ); \
if ( ! $result )
{
echo "I tried to ask for $sql<br>";
echo "but mysql didn't like it because:$sql<br>";
echo mysql_error();
}
else
{
$numrows = mysql_num_rows($result);
}
Part of the reason people seem to have so much confusion on this point is that failure, from the standpoint of mysql_query(), has nothing to do with the number of resulting rows found, if any. Rather, it strictly means that there was a syntax or permissions error that prevented the query from being carried out. The programmer, meanwhile, it short-circuiting the process and thinking, "Did I get any matching rows or not?"