How can the mysql_num_rows function be used to handle errors in PHP when querying a database?

When querying a database in PHP using MySQL functions, errors can occur if the query fails for any reason. One way to handle errors is to use the `mysql_num_rows` function to check if the query was successful and returned any rows. If the function returns false, it means there was an error in the query and you can handle it accordingly.

$result = mysql_query("SELECT * FROM table_name");

if (!$result) {
    die('Error in query: ' . mysql_error());
}

if (mysql_num_rows($result) > 0) {
    // Process the query results
} else {
    echo 'No rows found';
}

mysql_free_result($result);