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
- How can the isset function be used to check if a value is set in PHP?
- What could be the potential reasons for the "Warning: fopen()...failed to open stream: No such file or directory" error in a PHP script?
- What best practices should be followed when configuring PHP and MySQL to work together on an IIS server environment?