PHP - How to traverse an array of spokes?

0

I have the following code:

<?php while($row = mysql_fetch_array($alunosTurma)){ ?>
          <tr>
              <td><?php echo $row['NM_NIS_ALU']; ?></td>
              <td><?php echo $row['ST_NOME_ALU']; ?>
                <input type="hidden" value="<?php echo $row['ID_ALUNO_ALU']; ?>" name="aluno[]">
                <!-- <input type="hidden" value="<?php echo $idTurma; ?>" name="turma[]">
                <input type="hidden" value="<?php echo $dtChamada; ?>" name="data[]"> -->
              </td>
              <td class="text-center">
                <div class="btn-group" data-toggle="buttons">
                  <label class="btn btn-default">
                    <input type="radio" name="options[]" value="0"><i class="fa fa-check text-success"></i>
                  </label>
                  <label class="btn btn-default">
                    <input type="radio" name="options[]" value="1"><i class="fa fa-times text-danger"></i>
                  </label>
                </div>
              </td>
          </tr>
          <?php } ?>

This creates a table listing all the students and places two radios (one of presence and one of absence) in front of each one. In the file that makes the input in the database (or should) I have the following:

$data = $_GET['dtChamada'];
$turma = $_GET['idTurma'];
$aluno = $_POST['aluno'];
$status = $_POST['options'];
$cont = 0;
foreach ($aluno as $idAluno) {
mysql_query(" INSERT INTO CHAMADA (DT_CHAMADA_CHMD, ID_TURMA_TUR, ID_ALUNO_ALU, FL_STATUS_CHMD) VALUES ('$data', '$turma', '$idAluno[$cont]', '$status[$cont]') "));
print_r("$data<br>");
print_r("$turma<br>");
print_r("$aluno[$cont]<br>");
print_r("$status[$cont]<br><br>");
$cont++;
}
?>

For the first student the data arrives as accurate, but from the second on the status (presence or absence) gives the following error:

**Notice: Undefined offset: 1 in
C:\xampp\htdocs\NISFRAM\processa\lancaChamada.php on line 26**

How can I go through each student by recording their status in the bank?

    
asked by anonymous 23.09.2016 / 03:07

1 answer

0

The Table

<?php while($row = mysql_fetch_array($alunosTurma)){ ?>
          <tr>
              <td><?php echo $row['NM_NIS_ALU']; ?></td>
              <td><?php echo $row['ST_NOME_ALU']; ?>
                <input type="hidden" value="<?php echo $row['ID_ALUNO_ALU']; ?>" name="aluno[]">
                <!-- <input type="hidden" value="<?php echo $idTurma; ?>" name="turma[<?php echo $row['ID_ALUNO_ALU']; ?>]">
                <input type="hidden" value="<?php echo $dtChamada; ?>" name="data[<?php echo $row['ID_ALUNO_ALU']; ?>]"> -->
              </td>
              <td class="text-center">
                <div class="btn-group" data-toggle="buttons">
                  <label class="btn btn-default">
                    <input type="radio" name="options[<?php echo $row['ID_ALUNO_ALU']; ?>]" value="0"><i class="fa fa-check text-success"></i>
                  </label>
                  <label class="btn btn-default">
                    <input type="radio" name="options[<?php echo $row['ID_ALUNO_ALU']; ?>]" value="1"><i class="fa fa-times text-danger"></i>
                  </label>
                </div>
              </td>
          </tr>
          <?php } ?>

PHP

<?php
$data = $_GET['dtChamada'];
$turma = $_GET['idTurma'];
$aluno = $_POST['aluno'];
$status = $_POST['options'];

foreach ($aluno as $idAluno) {
mysql_query(" INSERT INTO CHAMADA (DT_CHAMADA_CHMD, ID_TURMA_TUR, ID_ALUNO_ALU, FL_STATUS_CHMD) VALUES ('$data', '$turma', '$idAluno', '$status[$idAluno]') "));
print_r("$data<br>");
print_r("$turma<br>");
print_r("$aluno[$idAluno]<br>");
print_r("$status[$idAluno]<br><br>");
}
?>
?>
    
23.09.2016 / 04:11