Ne fait pas la correction comme il le faudrait

Fermé
boni91 - Modifié le 8 sept. 2018 à 15:41
jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024 - 8 sept. 2018 à 15:46
Bonjour,

j'ai deux tableaux, 1 qui permet affiché les choix et 1 qui a les bonne réponses, quand je fais correction il me prend la première ligne en bonne réponse et les autres en mauvaises réponses malgré que normalement elle devrait être toutes bonnes.

voici un bout des tableaux:
'chx' => array(
'chiffre' => '1',
'reponse' => 'a',
'reponse1' => 'o',
'reponse2' => 'i',
'mot' => '',
'btn' => '../btn/oreille.png',
'mp3' => '../mp3_alphabet/A.mp3'
)  

tableau qui affiche les choix
$choix = array(
 'chx' => array('reponse_ok' => 'a'),
 'chx_1' => array('reponse_ok' => 'e'),
  'chx_2' => array('reponse_ok' => 'b'),
  'chx_3' => array('reponse_ok' => 'x'),
 'chx_4' => array('reponse_ok' => 'c'),
  'chx_5' => array('reponse_ok' => 'p'),
   'chx_6' => array('reponse_ok' => 'o'),
 'chx_7' => array('reponse_ok' => 'm'),
  'chx_8' => array('reponse_ok' => 'n'),
  'chx_9' => array('reponse_ok' => 'g'),
   'chx_10' => array('reponse_ok' => 's'),
  'chx_11' => array('reponse_ok' => 'u')
);

tableau avec les bonne réponses

foreach($reponses as $cle => $reponse)
{ 
if (isset($_POST['correction'])){
$clic = trim($_POST[$cle]);
foreach($choix as $key => $choi)
{
if((empty($clic) && empty($clic) !== $choi['reponse_ok'])){
echo '<article style="margin-left:39%">'; 
echo '<p style="font-size:1.2em;padding:0 20px;">'. $reponse['chiffre'] .'</p>';
echo'<p style="text-align:center;width:100px;font-size:1.2em;"><input style="margin:10px 0 0 0;" type="radio" name="' . $cle . '" value="' . $reponse['reponse'] .'" />'. $reponse['reponse'] .'</p>';
echo'<p style="text-align:center;width:100px;font-size:1.2em"><input style="margin:10px 0 0 0;"  type="radio" name="' . $cle . '" value="' . $reponse['reponse1'] .'" />'. $reponse['reponse1'] .'</p>';
echo'<p style="text-align:center;width:100px;font-size:1.2em"><input style="margin:10px 0 0 0;"  type="radio" name="' . $cle . '" value="' . $reponse['reponse2'] .'" />'. $reponse['reponse2'] .'</p>'; 

echo '<p><del style="color:red;">' . $clic . '</del></p>';
break;
}else 
 if (($clic == $reponse['reponse'] AND $reponse['reponse'] == $choi['reponse_ok']) OR ($clic == $reponse['reponse1'] AND $reponse['reponse1'] == $choi['reponse_ok']) OR ($clic == $reponse['reponse2'] AND $reponse['reponse2'] == $choi['reponse_ok']) )
{
echo '<article style="margin-left:39%">'; 
$point[$cle] = htmlspecialchars($clic); 
echo '<p style="font-size:1.2em;padding:0 20px;">'. $reponse['chiffre'] .'</p>';
echo'<p style="text-align:center;width:100px;font-size:1.2em;"><input style="margin:10px 0 0 0;" type="radio" name="' . $cle . '" value="' . $reponse['reponse'] .'" />'. $reponse['reponse'] .'</p>';
echo'<p style="text-align:center;width:100px;font-size:1.2em"><input style="margin:10px 0 0 0;"  type="radio" name="' . $cle . '" value="' . $reponse['reponse1'] .'" />'. $reponse['reponse1'] .'</p>';
echo'<p style="text-align:center;width:100px;font-size:1.2em"><input style="margin:10px 0 0 0;"  type="radio" name="' . $cle . '" value="' . $reponse['reponse2'] .'" />'. $reponse['reponse2'] .'</p>'; 

echo '<p>' . $point[$cle]. '</p><br />';
echo '</article>';
break;
}
else 
if (($clic != $reponse['reponse'] AND $reponse['reponse'] != $choi['reponse_ok']) OR ($clic != $reponse['reponse1'] AND $reponse['reponse1'] != $choi['reponse_ok']) OR ($clic != $reponse['reponse2'] AND $reponse['reponse2'] != $choi['reponse_ok']))
{ 
echo '<article style="margin-left:39%">';
$errors[$cle] = htmlspecialchars($clic);
var_dump($errors[$cle]);
echo '<p style="font-size:1.2em;padding:0 20px;">'. $reponse['chiffre'] .'</p>';
echo'<p style="text-align:center;width:100px;font-size:1.2em;"><input style="margin:10px 0 0 0;" type="radio" name="' . $cle . '" value="' . $reponse['reponse'] .'" />'. $reponse['reponse'] .'</p>';
echo'<p style="text-align:center;width:100px;font-size:1.2em"><input style="margin:10px 0 0 0;"  type="radio" name="' . $cle . '" value="' . $reponse['reponse1'] .'" />'. $reponse['reponse1'] .'</p>';
echo'<p style="text-align:center;width:100px;font-size:1.2em"><input style="margin:10px 0 0 0;"  type="radio" name="' . $cle . '" value="' . $reponse['reponse2'] .'" />'. $reponse['reponse2'] .'</p>'; 

echo '<p><del style="color:red;">' . $errors[$cle] . '</del></p><br />';
echo '</article>';
break;
}
}
}
}
echo '<br /><br />';
echo '<div style="display:inline-block;margin-left:-15em;margin-top:2em;" class="correction_center"><input type="submit" name="correction" value="correction"/></div>';
echo'</form>';
?>


voici le code pour la correction

auriez-vous une solution?
merci d'avance



A voir également:

2 réponses

bon je sais d’out ça vient, sait le break qui bloque, par contre auriez vous une solution pour que je n’ai pas 11 fois la mème ligne qui s'affiche par rapport a la boucle foreach($choix as $key => $choi) pour ne pas que ça se répète.
0
jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024 4 650
8 sept. 2018 à 15:46
Ce if est toujours faux
if((empty($clic) && empty($clic) !== $choi['reponse_ok'])){

A la limite :
if((empty($clic) && $clic !== $choi['reponse_ok'])){


Ensuite, tu ne devrais pas faire deux boucles....
Une seule sur les questions ($choix) suffit. et dans cette boucle tu regardes si la réponse correspondante est la bonne ou non.

0