0
I have a dynamic table in HTML which brings the following result:
The columns Português and Mathematics, comes from the database and are dynamic, ie may contain more materials. The same occurs with the column Students, which is also dynamic and comes from the database.
Note that Fernando Pessoa’s notes are: Portuguese 11 and Mathematics 12 and Santos Dumont’s is Portuguese 13 and Mathematics 14.
To generate this table, I did it as follows. (correct me if I’m done wrong):
public function materiasNotas($idEscolas,$idTurmas){
.....
$listar = "<table class=\"table table-bordered\">
<thead>
<tr>
<th style='background-color: #4682B4; color: #FFF; text-align: center'>Alunos</th>";
while($jmListar = mysqli_fetch_object($sqlListar)){
$listar .= "<th style='background-color: #4682B4; color: #FFF; text-align: center'>".$jmListar->Materias."</th>";
}
$listar .= "<th style='background-color: #4682B4; color: #FFF; text-align: center'>Boletim</th>
</tr>
</thead>";
$sqlAlunos = mysqli_query($this->conexao,"SELECT * FROM pe_cadastros_alunos WHERE IdEscolas = '".$idEscolas."' AND IdTurmas = '".$idTurmas."';");
while($jmAlunos = mysqli_fetch_object($sqlAlunos)){
$listar .= "<tbody>";
$listar .= "<td style='background-color: #B0C4DE'><input type='text' name='Alunos[]' value='".$jmAlunos->NomeCompleto."' style='border: 0; background-color: #B0C4DE;' readonly></td>";
//$i = 1;
$sqlMat = mysqli_query($this->conexao,"SELECT * FROM pe_materias WHERE IdEscolas = '".$idEscolas."' AND IdSeries = '".$jmTurmas->Series."';");
while($jmMat = mysqli_fetch_object($sqlMat)){
$listar .= "<td><div align='center'><input type='hidden' name='Materias[]' value='".$jmMat->Materias."'><input type='text' name='Notas[]' placeholder='Nota' style='width: 100px'></div></td>";
}
$listar .= "<td><div align='center'><button class='btn btn-success btn-xs'><i class=\"fa fa-print fa-lg\" aria-hidden=\"true\"></i> Imprimir</button> <button class='btn btn-success btn-xs'><i class=\"fa fa-envelope fa-lg\" aria-hidden=\"true\"></i> E-mail</button> <button class='btn btn-success btn-xs'><i class=\"fa fa-download fa-lg\" aria-hidden=\"true\"></i> Baixar</button></div></td>";
$listar .= "</tbody>";
}
$listar .= "</table>";
return $listar;
}
The problem is time to register in the database, because it is returning me this way:
Note that the names are not matching with the notes cited above, IE, in the second line was to be Fernando Pessoa and Santos Dumont was to stay in the third and fourth lines.
I’m registering that way:
public function cadastrarNotasAlunos($idEscola,$aluno,$bimestre,$materias,$notas,$situacao){
....
for($i = 0; $i <= count($notas) - 1; $i++){
mysqli_query($this->conexao, "INSERT INTO pe_notas_alunos VALUES(null,'".$idEscola."','".$aluno[$i]."','".$materias[$i]."','".$notas[$i]."','". $bimestre."','".$situacao."');");
}
}
How I would have the names registered according to your notes?
Hello Felipe. Actually the student is a matrix name='Students[]'
– user24136
The problem is exactly there when you pass the student matrix with 2 elements and the note matrix with 4 elements and iterate with the same variable.
– Felipe Miranda
Got it.... could you give me an example? Because I really don’t know what to do...
– user24136
Hello Felipe. I will try with your code...
– user24136