How can you modify the PHP script to display a message like "0 Treffer" when no results are found in the SQL query?
To display a message like "0 Treffer" when no results are found in the SQL query, you can check the number of rows returned by the query. If the number of rows is zero, then display the message. You can achieve this by using the `mysqli_num_rows()` function to get the number of rows returned by the query and then conditionally display the message based on that count.
<?php
// Perform your SQL query here
$query = "SELECT * FROM your_table WHERE your_condition";
$result = mysqli_query($connection, $query);
// Check if there are any results
if(mysqli_num_rows($result) == 0) {
echo "0 Treffer";
} else {
// Display your results here
while($row = mysqli_fetch_assoc($result)) {
// Display your results
}
}
// Free result set
mysqli_free_result($result);
// Close connection
mysqli_close($connection);
?>
Keywords
Related Questions
- What are the best practices for creating a dynamic form in PHP that can be easily managed through an admin interface?
- What are the best practices for handling link styles in PHP?
- Are there alternative PHP libraries or tools that can simplify the process of parsing and rendering BBCode content while avoiding issues with line breaks?