我的计算机老师要我做一个简单的 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();
?>
最佳答案
单选按钮按名称分组。第一个答案的示例: 什么过程决定了用户的身份?
<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">
应该使用而不是 radio
.
关于php - 添加单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12742250/