php代码只会在放入按钮时显示字符串中的第一个单词

时间:2017-03-31 20:42:25

标签: php sql arrays button shuffle

我使用带有问题的数据库和答案为学校项目制作一种测验网站,它必须在php中。问题和答案取自数据库,然后洗牌并放在按钮中。出于某种原因,虽然我只看到了第一个单词。例如,按钮将显示新的而不是纽约。然而,当我让他们回应时,我显示的答案是完整的字符串。此问题的字符串也正常。

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>';
                }

我试过改变&#34; &#39;但似乎没什么用。 $ a0-3就是答案。

0 个答案:

没有答案