How can the code be modified to accurately determine if a query has returned any results?
To accurately determine if a query has returned any results, we can check the number of rows returned by the query. If the number of rows is greater than 0, then the query has returned results. We can use the mysqli_num_rows() function to achieve this.
// Execute the query
$result = mysqli_query($connection, $query);
// Check if any results were returned
if(mysqli_num_rows($result) > 0) {
// Results were found
while($row = mysqli_fetch_assoc($result)) {
// Process the results
}
} else {
// No results found
echo "No results found.";
}