How can PHP be used to retrieve and display specific thread information based on category ID in a forum?
To retrieve and display specific thread information based on category ID in a forum, you can use PHP to query the database for threads that belong to the specified category ID. You can then loop through the results and display the relevant information such as thread title, author, and date.
<?php
// Connect to the database
$pdo = new PDO('mysql:host=localhost;dbname=forum_db', 'username', 'password');
// Category ID to retrieve threads for
$category_id = 1;
// Query to retrieve threads based on category ID
$stmt = $pdo->prepare('SELECT * FROM threads WHERE category_id = :category_id');
$stmt->execute(['category_id' => $category_id]);
// Display thread information
while ($row = $stmt->fetch()) {
echo 'Title: ' . $row['title'] . '<br>';
echo 'Author: ' . $row['author'] . '<br>';
echo 'Date: ' . $row['date'] . '<br>';
echo '<br>';
}
?>