How can you check if a database query returned no results in PHP?
When executing a database query in PHP, you can check if it returned no results by examining the number of rows returned by the query. If the number of rows is zero, then the query did not find any matching records in the database.
// Execute the database query
$result = mysqli_query($conn, "SELECT * FROM table_name WHERE condition");
// Check if the query returned no results
if(mysqli_num_rows($result) == 0) {
echo "No results found.";
} else {
// Process the results
while($row = mysqli_fetch_assoc($result)) {
// Do something with the data
}
}