How can PHP and MySQL be effectively used together to filter and display data based on user input, such as a selected year?

To filter and display data based on user input, such as a selected year, you can use PHP to retrieve the user input and construct a MySQL query to fetch the relevant data from the database. You can then display the filtered data on the webpage using PHP.

<?php
// Retrieve user input for selected year
$selected_year = $_POST['selected_year'];

// Connect to MySQL database
$connection = mysqli_connect('localhost', 'username', 'password', 'database_name');

// Construct MySQL query to fetch data based on selected year
$query = "SELECT * FROM table_name WHERE YEAR(date_column) = $selected_year";
$result = mysqli_query($connection, $query);

// Display filtered data
while ($row = mysqli_fetch_assoc($result)) {
    echo $row['column_name'] . "<br>";
}

// Close database connection
mysqli_close($connection);
?>