How can the error "mysql_num_rows() expects parameter 1 to be resource, boolean given" be resolved when using mysql_query in PHP?

The error "mysql_num_rows() expects parameter 1 to be resource, boolean given" occurs when the mysql_query function in PHP fails to execute the query and returns a boolean value (false) instead of a resource. To resolve this issue, you should check if the query was executed successfully before using mysql_num_rows() function by verifying the return value of mysql_query.

$result = mysql_query($query);

if($result){
    $row_count = mysql_num_rows($result);
    // Further processing of the result
} else {
    // Handle query execution failure
}