How to list all answers

Asked

Viewed 40 times

0

Colleagues. I have the following code:

$array = array("A","B","C","D","E");
echo "<div style='font-size: 18px; text-align: left: font-weight: bold'>Olá, ".$nome."</div>";
echo "<br>";
echo "<div style='width: 100%; background-color:#0070C0; color: #FFF; text-align: center; font-size: 16px; font-weight: bold'>".$xml->avaliacao->disciplina['nome']."</div>";
echo "<br>";
echo "<div style='width: 100%; background-color:#eaeaea; text-align: center; font-size: 16px; font-weight: bold'>".$xml->avaliacao['segmento']. " Série.: " .$xml->avaliacao['serie']."</div>";
echo "<br><br>";    
echo "Preencha abaixo as questões:";
echo "<br><br>";

$c = 1;
for($contar = 0; $contar < $xml->avaliacao['questoes']; $contar++){

    echo "<div style='width: 100%; background-color:#FFFBA6; text-align: left; color: #0070C0; font-weight: bold'> QUESTÃO " .$c.":</div>";
    echo "<br>";

    foreach($array as $opcao) {
        echo $opcao . ": <input type='radio' name='respostas[".$contar."]' value='".$opcao."' ".$checked.">" . "<br>";
    }
$c++;
}

Through an XML file, I bring the questions of a file for the user to mark the answers. To get the answers, I am doing so:

foreach($xml->avaliacao->disciplina->questao as $listar => $valor) {           

                    $numero =  $valor["numero"];
                echo $numero;
                    $respostas = $valor->resposta;

        if($_POST["respostas"][$c] == $respostas){
            $valor = "1";
            $somar[0] = $cc++;

                        $respostasC = str_pad($_POST["respostas"][$c], 2);
            $respostasCorretas = implode(', ', explode(' ', $respostasC));

                        echo "Corretas " .$respostasCorretas;
                        echo "<br>";
        }else{
            $valor = "0";
            $somarE[0] = $cc++;

                        $respostasE = str_pad($_POST["respostas"][$c], 2);
            $respostasErradas = implode(', ', explode(' ', $respostasE));
            echo "Erradas " .$respostasErradas;
                        echo "<br>";
        }
        $c++;
        //$respostas = array("",$_POST["respostas"][$c]);
    }

So far it works perfectly, but if there are 20 questions, it only lists the first 10. They can tell me why it happens?

1 answer

0

Probably the error is in your stop condition loop:

for ($contar = 0; $contar < $xml->avaliacao['questoes']; $contar++) {

If the key questoes is a list of questions, and not the amount of them, you will have to exchange the code for the following:

for ($contar = 0; $contar < count($xml->avaliacao['questoes']); $contar++) {

Browser other questions tagged

You are not signed in. Login or sign up in order to post.