What are potential pitfalls to avoid when using mysql_fetch_array to display results in PHP?

One potential pitfall to avoid when using mysql_fetch_array to display results in PHP is not checking if the result set is empty before trying to fetch data. This can lead to errors if there are no rows returned from the query. To avoid this, you should always check if there are rows to fetch before attempting to display them.

$result = mysql_query("SELECT * FROM table");
if(mysql_num_rows($result) > 0) {
    while($row = mysql_fetch_array($result)) {
        // Display data here
    }
} else {
    echo "No results found.";
}