<?php
// Database connection
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "elvieg_editpost";

$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Fetch data based on selected option
$option = $_POST['option'];
$sql = "SELECT * FROM vitalstatistic2022to2026 WHERE ctrlnum = '$option'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    echo "<table class='table table-striped'>";
    echo "<thead>";
    echo "<tr><th>Ctrlnum</th><th>MBO</th><th>Code</th><th>Category</th><th>Description</th> <th>2022 Perform </th><th>2023 Perform </th><th>Remarks 2023 </th></tr>";
    echo "</thead>";
    echo "<tbody>";
    while ($row = $result->fetch_assoc()) {
        echo "<tr>";
        echo "<td>" . $row['ctrlnum'] . "</td>";
        echo "<td>" . $row['mbo'] . "</td>";
        echo "<td>" . $row['indicatorcode'] . "</td>";
        echo "<td>" . $row['category'] . "</td>";
        echo "<td>" . $row['description'] . "</td>";
        echo "<td>" . $row['y2022'] . "</td>";
        echo "<td>" . $row['y2023'] . "</td>";
        echo "<td>" . $row['remark2023'] . "</td>";
        echo "</tr>";
    }
    echo "</tbody>";
    echo "</table>";
} else {
    echo "No data found";
}
$conn->close();
?>