What are the potential pitfalls of using an empty result check within a while loop in PHP?

Using an empty result check within a while loop in PHP can lead to an infinite loop if the result set is not properly fetched or if the query does not return any rows. To solve this issue, it is important to include a condition within the while loop that checks if there are any rows left to fetch from the result set.

// Example of implementing a check for empty result set within a while loop
$result = mysqli_query($connection, "SELECT * FROM table");

if(mysqli_num_rows($result) > 0) {
    while($row = mysqli_fetch_assoc($result)) {
        // Process each row here
    }
} else {
    echo "No rows found in the result set";
}