How can PHP be used to organize and display comments under specific news headlines in a structured manner?

To organize and display comments under specific news headlines in a structured manner using PHP, you can create a database table to store comments with a foreign key referencing the news headline they belong to. Then, retrieve and display comments for a specific news headline by querying the database based on the headline's ID.

// Assuming you have a database connection established

// Retrieve news headline ID from the URL or wherever it's stored
$headline_id = $_GET['headline_id'];

// Query database for comments related to the specific news headline
$sql = "SELECT * FROM comments WHERE headline_id = $headline_id";
$result = mysqli_query($conn, $sql);

// Display comments in a structured manner
while ($row = mysqli_fetch_assoc($result)) {
    echo "<div class='comment'>";
    echo "<p>{$row['comment_text']}</p>";
    echo "<p>Posted by: {$row['user']}</p>";
    echo "</div>";
}