How can the num_rows property of a database class be utilized in PHP to determine if a search query returned any results?

To determine if a search query returned any results, you can utilize the num_rows property of a database class in PHP. After executing the search query, you can check the value of num_rows to see if it is greater than 0, indicating that results were found. This can help you determine whether to display the search results or a message indicating no results were found.

// Execute search query
$result = $db->query("SELECT * FROM table WHERE column = 'value'");

// Check if results were found
if ($result->num_rows > 0) {
    // Display search results
    while ($row = $result->fetch_assoc()) {
        // Display search results
    }
} else {
    // Display message indicating no results were found
    echo "No results found.";
}