What best practices can be implemented to prevent the exclusion of the first dataset when using mysql_fetch_assoc in PHP?

When using mysql_fetch_assoc in PHP to fetch rows from a database, the first dataset may be excluded if not handled properly. To prevent this, you can check if there are any rows returned before fetching the data. This can be done by using mysql_num_rows to determine if there are any rows in the result set before fetching the data.

$result = mysql_query("SELECT * FROM table");
if(mysql_num_rows($result) > 0) {
    while($row = mysql_fetch_assoc($result)) {
        // Process the data here
    }
} else {
    echo "No rows found";
}