<?php 
$host = "localhost";
$user = "kaltekgo_admin";
$pass = "kaltek@2024";
$db   = "kaltekgo_avila";

$conn = new mysqli($host, $user, $pass, $db);
if ($conn->connect_error) {
    die("Erro: " . $conn->connect_error);
}

$id_turma = $_POST['id_turma'] ?? 0;

$sql = "SELECT a.matricula, a.nome, 
               t.identificador_turma AS turma, 
               t.identificador_serie AS serie, 
               a.nota
        FROM alunos_fundamental1 a
        JOIN serie_turma_turno t ON a.id_turma = t.id_serie_turma
        WHERE a.id_turma = ?
        ORDER BY a.nome";

$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $id_turma);
$stmt->execute();
$res = $stmt->get_result();

while ($row = $res->fetch_assoc()) {
    // Se for NULL ou 0, exibe em branco
    $nota = (!is_null($row['nota']) && $row['nota'] != 0) ? $row['nota'] : '';

    echo "
    <tr>
        <td class='hidden-xs'>{$row['matricula']}</td>
        <td>{$row['nome']}</td>
        <td class='hidden-xs'>{$row['serie']}</td>
        <td class='hidden-xs'>{$row['turma']}</td>
        <td>
            <input 
                type='number' 
                name='nota[{$row['matricula']}]'
                class='form-control nota' 
                min='0' max='10' step='0.01'
                value='{$nota}'
                style='max-width:100px;'>
        </td>
    </tr>
    ";
}
?>
