Mysql
 sql >> Datenbank >  >> RDS >> Mysql

php Multiple-Choice-Quiz-Ersteller

Dies sind klassische HTML-Formulare. Sie haben ein Formular wie dieses:

<?php
    $row = mysql_fetch_array(mysql_queryy('select * yourtable order by rand() limit 1'),MYSQL_ASSOC);
    $question = $row['question'];
    unset($row['question']);
    shuffle($row);
?>
<form method="post" action="other_script.php?q=<?php echo $question; ?>">
    <p><?php echo $question; ?></p>
    <?php
        foreach ($row as $key => $value) {
            echo "<input type='radio' name='answer'>".$value."</input>
            ";
        }
    ?>
    <input type="submit">Submit</input>
</form>

Und dann Ihre other_script.php Seite würde so aussehen:

<?php
    $ans = mysql_result(mysql_query('select c_answer from yourtable where question = "'.url_decode($_GET['q']).'"'),0);
    if ($_POST['answer'] == $ans){
        echo "You got it right!";
    }else{
        echo "You got it wrong!";
    }
?>