我目前正在创建在线测验。为了让我从输入中检索信息,我想我需要为单选按钮输入一个值。我希望输入第一个值为1,第二个值为2等等。因为我在php中使用了这个echo,我假设它必须是某种变量?
我尝试过不同的循环,但我似乎无法让它发挥作用。很抱歉,这听起来像一个简单的问题。任何帮助,将不胜感激!
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<title>Online Quiz</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<div>
<form action="" method="post" id="quiz">
<?php
require'./quizData.php';
include('Header.php');
foreach ($quizSGHistoryQ as $questionNo => $questionInfo) {
echo "<br>" . $questionNo . ")";
echo $questionInfo['question'];
echo $questionInfo['answer'] . "<br>";
foreach ($questionInfo['options'] as $option => $desc) {
echo "<input type= 'radio' name = " . $questionNo . " >" . $desc . "<br>";
}
}
include('Footer.php');
?>
<input type="submit" name="submit" value="Submit">
</form>
</div>
<?php
foreach ($quizSGHistoryQ as $questionNo => $questionInfo) {
$pickedAns = $_POST [$questionNo];
$totalScore = 0;
if ($pickedAns == $questionInfo['answer']) {
$totalScore++;
}
}
?>
</body>
</html>
答案 0 :(得分:0)
我改变了你的代码如下:
foreach ($questionInfo['options'] as $option => $desc)
{
$key++;
echo "<input value='".$key."' type= 'radio' name = " . $questionNo . " >" . $desc . "<br>";
}