What could be causing the PHP Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in this code snippet?

This warning typically occurs when the mysqli_query() function fails to execute the SQL query properly, resulting in a boolean value (false) being returned instead of a mysqli_result object. To solve this issue, you should check if the query execution was successful before using mysqli_num_rows() function. This can be done by verifying the return value of mysqli_query() and handling the error accordingly.

// Check if the query executed successfully
$result = mysqli_query($connection, $query);
if($result) {
    // Use mysqli_num_rows() on the result set
    $num_rows = mysqli_num_rows($result);
    
    // Process the result set
    if($num_rows > 0) {
        // Fetch and display data
    } else {
        echo "No results found.";
    }
} else {
    echo "Error executing query: " . mysqli_error($connection);
}