0

I'm using a database with questions and the answers to make a kind of quiz site for a school project it has to be in php. The question and answers are taken from the data base then shuffled and placed in buttons. For some reason though I only see the first word from. The buttons will show new instead of new york for example. However when I have them echo'd out the answers I am shown are the full string. Also the string for the question works fine.

foreach($resultaat as $row) {                               
                $ar=array($row['a'],$row['b'],$row['c'],$row['d']);
                shuffle($ar);
                $random_keys=array_rand($ar,4);
                echo $row['vraag']."<br>";
                $forma = '<form action="check.php" name="mijnform" method="post"><input type="hidden" name="vraag" value="4"><input type="hidden" name="score" value="250000">';
                $formb = '<input type="hidden" name="voornaam" value='.$voornaam.'><input type="hidden" name="achternaam" value='.$achternaam.'>
                <input type="hidden" name="email" value='.$email.'><input type="hidden" name="str" value='.$str.'>';
                $a0 = $ar[$random_keys[0]];
                $a1 = $ar[$random_keys[1]];
                $a2 = $ar[$random_keys[2]];
                $a3 = $ar[$random_keys[3]];
                $f = $forma. $formb .'<input type="submit" name="antwoord" value='.$a0.'></form>';
                $g = $forma. $formb .'<input type="submit" name="antwoord" value='.$a1.'></form>';
                $h = $forma. $formb .'<input type="submit" name="antwoord" value='.$a2.'></form>';
                $i = $forma. $formb .'<input type="submit" name="antwoord" value='.$a3.'></form>';
                echo $a0;
                echo $a1;
                echo $a2;
                echo $a3;
            if (isset($_POST['button3'])) { 
                $ar=array($row['a'],$row['b']);
                shuffle($ar);
                $random_keys=array_rand($ar,2);
                echo "$f";
                echo "$g";
                echo '<br>';
            }
            else{
                $ar=array($row['a'],$row['b'],$row['c'],$row['d']);
                shuffle($ar);
                $random_keys=array_rand($ar,4);
                echo "$f";
                echo "$g";
                echo "$h";
                echo "$i";
                echo '<br>';
                }

I've tried changing the " ' but nothing seems to work. The $a0-3 are the answers.

Pilo
  • 1

0 Answers0