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 JavaScript be used to create a form and submit data without displaying variables in the address bar when passing them through a link in PHP?
- How can PHP developers effectively use $smarty->assign in a separate class like CORE.class.php?
- How can one ensure that only *.tpl and *.css files are parsed and used by the template parser in PHP?