Get data from a dynamic HTML table

0

I have a dynamic HTML table that has the following result:

ThecolumnsPortugueseandMathematics,comefromthedatabaseandaredynamic,thatis,theycancontainmoresubjects.ThesamehappenswiththeStudentscolumn,whichisalsodynamicandcomesfromthedatabase.

PleasenotethatFernandoPessoa'sgradesare:Portuguese11andMathematics12andSantosDumontisPortuguese13andMathematics14.

Togeneratethistable,Ididthefollowing.(correctmeifI'mdonewrong):

publicfunctionmateriasNotas($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 the time to register in the database, as it is returning me this way:

Note that the names are not beating with the notes quoted above, ie in the second line was to stay Fernando Pessoa and Santos Dumont was to stay on the third and fourth lines.

Iamregisteringthisway:

publicfunctioncadastrarNotasAlunos($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 would I do to have the names registered according to your notes?

    
asked by anonymous 23.07.2017 / 00:29

1 answer

1

Friend I believe that in its role of enrolling the student is not a matrix but a constant. No need to increase if more than one note comes.

mysqli_query($this->conexao, "INSERT INTO pe_notas_alunos VALUES(null,'".$idEscola."','".$aluno."','".$materias[$i]."','".$notas[$i]."','".   $bimestre."','".$situacao."');");

php is not my strong, the ideal solution would be the creation of the pe_notas_alunos object and an array of student_notes would be sent.

But I believe that this code below should work

for($a = 0; $a <= count($aluno) - 1; $a++){  
    for($i = a*(count($notas)/count($aluno)) $i <= (count($notas)/count($aluno)) + a*(count($notas)/count($aluno)) - 1; $i++){
          mysqli_query($this->conexao, "INSERT INTO pe_notas_alunos VALUES(null,'".$idEscola."','".$aluno[$a]."','".$materias[$i]."','".$notas[$i]."','".   $bimestre."','".$situacao."');");
    }
}
    
23.07.2017 / 03:31