1

我的电脑老师要我做一个简单的 php mySql 数据库多项选择测验,但现在我被卡住了。我已经制作了 input-form.php。因此,当他进入页面时,他可以输入问题和多项选择答案。到目前为止,我的工作是 input-form.php 和 quiz1.php,它们显示数据库中的内容。我现在需要有关如何使用多项选择答案旁边的单选按钮的帮助,以便学生可以阅读问题并单击正确的答案。在他们阅读并单击那里的选项后,当他们点击提交时,它将向老师发送一封测试电子邮件,其中包含问题和多项选择答案以及他们选择的答案。

测试:

What process determines the identity of a user? 
A. Authentication 
B. tt4ert4t 
C. 4tt4t 
D. 4tt4 

Which of the following user account types can create other user accounts? 
A. uyiyuiy 
B. iuyiuiiu 
C. Administrator 
D. uykuykuyikuy 

To which of the following groups does a standard user in Windows 2000 belong by default? (Select two.) 
A. Limited Users 
B. Power Users 
C. Restricted Users 
D. Users 

等等 ....

php代码:

<?php

// connect to your MySQL database here 
require_once "db_connect.php"; 

// Build the sql command string 
$sqlCommand = "SELECT `question`, `a`, `b`, `c`, `d` FROM `quiz1`"; 
// Execute the query here now 
$query = mysql_query($sqlCommand) or die (mysql_error()); 
// Output the data here using a while loop, the loop will return all members 
while ($row = mysql_fetch_array($query)) { 
// Gather all $row values into local variables for easier usage in output
$question = $row["question"];
$a = $row["a"];
$b = $row["b"];
$c = $row["c"];
$d = $row["d"];


// echo the output to browser 
echo "$question
<br />A. $a 
<br />B. $b 
<br />C. $c
<br />D. $d
<br /><hr />"; 
  } 
 // Free the result set if it is large 
 mysql_free_result($query);  
 // close mysql connection 
 mysql_close(); 

 ?>
4

2 回答 2

1

单选按钮按名称分组。第一个答案的示例:什么过程确定用户的身份?

<p>What process determines the identitiy of a user?</p>
<ol>
    <li><label><input type="radio" name="q1" value="1">Authentication</label></li>
    <li><label><input type="radio" name="q1" value="2">tt4ert4t</label></li>
    <li><label><input type="radio" name="q1" value="3">4tt4t</label></li>
    <li><label><input type="radio" name="q1" value="4">4tt4</label></li>
</ol>

<label>当您单击标签本身并选择单选按钮时,拥有该元素会提供很好的免费功能(试试看!)。此外,该<ol>元素定义了一个有序列表。


对于有多个选项的问题,<input type="checkbox">应使用 a 而不是radio

于 2012-10-05T08:21:50.500 回答
0

您应该对多个答案使用复选框:

echo "$question
<br /><input type='checkbox' name='answer[]' value='$a' />A. $a 
<br /><input type='checkbox' name='answer[]' value='$b' />B. $b 
<br /><input type='checkbox' name='answer[]' value='$c' />C. $c
<br /><input type='checkbox' name='answer[]' value='$d' />D. $d
<br /><hr />"; 

或多个问题:

name='answer[$id][]' // where $id is the id of the question.

在下一页上,您将获得一个$_POST['answer']包含所有选定答案的数组。

于 2012-10-05T08:20:42.227 回答