there might a problem on how it fetched the data. the data is not showing on the input field. what seems to be the problem? I tried to change the approach so many times but it is still the same. what am I missing out here?
query($year_query); //
Initialize default variables $data = []; $selected_year = ”;
$months = get_months(); // Get an array of months // Fetch months
dynamically function get_months() { return [
“1” => “January”, “2” => “February”, “3” => “March”, “4” => “April”,
“5” => “May”, “6” => “June”, “7” => “July”, “8” => “August”,
“9” => “September”, “10” => “October”, “11” => “November”, “12” => “December” ]; } // Handle form submission if ($_SERVER[“REQUEST_METHOD”] == “POST”) { // Update form logic if
(isset($_POST[‘data’]) && isset($_POST[‘year’])) {
$selected_year = $_POST[‘year’];foreach ($_POST[‘data’] as $month => $values) {
$total_nr = $values[‘total_nr’] ?? 0;
$re_enlisted_personnel = $values[‘re_enlisted_personnel’] ?? 0;
$reprimand = $values[‘reprimand’] ?? 0;
$not_yet_re_enlisted = $values[‘not_yet_re_enlisted’] ?? 0;$update_query = ”
UPDATE reenlistment_data
SET
total_nr = ‘$total_nr’,
re_enlisted_personnel = ‘$re_enlisted_personnel’,
reprimand = ‘$reprimand’,
not_yet_re_enlisted = ‘$not_yet_re_enlisted’
WHERE
year = ‘$selected_year’
AND month = ‘$month’
“;
$conn->query($update_query);
}echo “Data updated successfully for $selected_year!”; }
// Fetch data for the selected year if (isset($_POST[‘year’])) {
$selected_year = $_POST[‘year’];
$data_query = “SELECT * FROM reenlistment_data WHERE year = ‘$selected_year’ ORDER BY month ASC”;
$data_result = $conn->query($data_query);// Prepare data for form rendering
if ($data_result) {
while ($row = $data_result->fetch_assoc()) {
$data[$row[‘month’]] = $row;
}
} } } ?> content=”width=device-width, initial-scale=1.0″> Update
Re-enlistment Data
Update Re-enlistment DataSelect Year:
Select Year
fetch_assoc()): ?>” >
Load Data
“>
Month
Total NR
Re-enlisted Personnel
Reprimand
Not Yet Re-enlisted$month_name):
$row = $data[$month_num] ?? [‘total_nr’ => ”, ‘re_enlisted_personnel’ => ”, ‘reprimand’ => ”,
‘not_yet_re_enlisted’ => ”];
?>][total_nr]”
value=””>
][re_enlisted_personnel]” value=””>
][reprimand]”
value=””>
][not_yet_re_enlisted]” value=””>Update Data
No data available for the selected year.