What potential pitfalls should be avoided when using the mysql_num_rows function in PHP?

When using the mysql_num_rows function in PHP, one potential pitfall to avoid is not checking if the query was successful before calling mysql_num_rows. If the query fails, mysql_num_rows will return false, leading to unexpected results. To avoid this, always check if the query was successful before using mysql_num_rows.

// Check if the query was successful before using mysql_num_rows
$result = mysql_query($query);
if($result){
    $num_rows = mysql_num_rows($result);
    echo "Number of rows: " . $num_rows;
} else {
    echo "Query failed";
}