How can PHP be used to retrieve data from a database based on a selected category?

To retrieve data from a database based on a selected category in PHP, you can use SQL queries with a WHERE clause to filter the results based on the selected category. You can pass the selected category as a parameter in the SQL query to dynamically retrieve data based on the user's selection.

<?php
// Assuming you have already established a database connection

// Get the selected category from user input
$selectedCategory = $_GET['category'];

// Prepare and execute SQL query to retrieve data based on the selected category
$sql = "SELECT * FROM your_table WHERE category = :category";
$stmt = $pdo->prepare($sql);
$stmt->execute(['category' => $selectedCategory]);

// Fetch and display the retrieved data
while ($row = $stmt->fetch()) {
    echo $row['column_name'];
}
?>