How can the issue of not entering the while loop when the query result is empty be addressed in PHP?

Issue: The problem of not entering the while loop when the query result is empty can be addressed by checking if there are any rows returned before entering the loop. This can be done by using the mysqli_num_rows() function to determine if there are any results to iterate over.

// Check if there are any rows returned before entering the while loop
if(mysqli_num_rows($result) > 0) {
    // Iterate over the query results
    while($row = mysqli_fetch_assoc($result)) {
        // Process each row here
    }
} else {
    // Handle the case when no results are returned
    echo "No results found.";
}