Forum Moderators: coopster
<?php
function error($myproblem) {
echo "<b> $myproblem </b>";
}
//question for my quizz
$monquizz=array (
array ("1","i am ","at","home"),
array ("2","i go","to","university"),
array ("3","i drink","my","beer"),
);
//end
$reponse = array(); // vide, destiné à recevoir les saisies
$saisie_reponse[] = ""; // saisies postées via formulaire
if (isset($_POST['action']))
{
for ($i=0; $i<count($monquizz); $i++) {
foreach ($_POST['saisie_reponse'] as $reponse){
$correct=$monquizz[$i][2];//la bonne reponse
echo "$correct $reponse<br>";
}//end of for
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Document sans titre</title>
</head>
<body>
<form id="quizz" name="quizz" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?php
foreach($saisie_reponse as $reponse){
for ($i=0; $i<count($monquizz); $i++) {
$question="question".$monquizz[$i][0];
echo $monquizz[$i][1];
?>
<input type="text" name="saisie_reponse[]" value="<?php echo $reponse; ?>" size="30" maxlength="35">
<?php
echo $monquizz[$i][3];
echo"<br>";
echo"<br>";
}
}
?> <label>
<input name="action" type="hidden" value="valider" />
<input type="submit" name="$ajout_reponse" value="Envoyer" />
</label>
</form>
<p>
</p>
<p> </p>
<p> </p>
<p> </p>
</body>
</html>
Thanks in advance
Hanlin
But $saisie_reponse is an empty array before the form has been submitted, so the loop won't display anything. Remove the foreach and its corresponding }.
You'll also want to add some markup between the questions or they'll all get stuck together on one line. Something like this perhaps:
echo "<p>" . $question . $monquizz[$i][1] . "</p>";