我在这里有一个应用程序:应用程序
我所拥有的是一些问题,并与复选框按钮中可能的答案中的每个问题相关联,以及三个文本输入显示 questionId、选项类型和每个单独答案的标记数。
实际上,如果我遇到问题,每个答案的分数。我想尝试的是,对于每个问题的每个正确答案,它们都与自己的文本输入相关联,显示它们值得的分数(在下面的 Individual_Answer 表中找到),否则对于所有不正确的答案,它们都值得0
在他们的文本输入/
现在这里是此示例应用程序的数据库表:
问题:
QuestionId (PK auto) QuestionNo SessionId (FK Session) OptionId (FK Option)
72 1 26 3
73 2 26 4
选项表:
OptionId (PK Auto) OptionType
1 A-C
2 A-D
3 A-E
4 A-F
回答:
AnswerId (PK auto) QuestionId (FK Question) Answer
1 72 C
2 73 A
3 73 C
4 73 D
个人回答:
AnswerId (PK auto) AnswerMarks
1 2
2 2
3 1
4 2
实际代码如下:
//$qandaqry query is here and executed
$qandaqrystmt->bind_result($qandaQuestionId,$qandaQuestionNo,$qandaQuestionContent,$qandaOptionType,$qandaAnswer,$qandaAnswerMarks );
$arrQuestionId = array();
$arrQuestionNo = array();
$arrQuestionContent = array();
$arrOptionType = array();
$arrAnswer = array();
$arrAnswerMarks = array();
while ($qandaqrystmt->fetch()) {
$arrQuestionId[ $qandaQuestionId ] = $qandaQuestionId; //QuestionId
$arrQuestionNo[ $qandaQuestionId ] = $qandaQuestionNo; //QuestionNo
$arrQuestionContent[ $qandaQuestionId ] = $qandaQuestionContent; //QuestionContent
$arrOptionType[ $qandaQuestionId ] = $qandaOptionType; //OptionType
$arrAnswer[ $qandaQuestionId ] = $qandaAnswer; //Answer
$arrAnswerMarks[ $qandaQuestionId ] = $qandaAnswerMarks; //AnswerMarks
}
?>
<form action='results.php' method='post' id='exam'>
<?php
//Retrieve options for each question
function ExpandOptionType($option) {
$options = explode('-', $option);
if(count($options) > 1) {
$start = array_shift($options);
$end = array_shift($options);
do {
$options[] = $start;
}while(++$start <= $end);
}
else{
$options = explode(' or ', $option);
}
echo '<p>';
foreach($options as $indivOption) {
echo '<div class="ck-button"><label class="fixedLabelCheckbox"><input type="checkbox" name="options[]" id="option-' . $indivOption . '" value="' . $indivOption . '" /><span>' . $indivOption . '</span></label></div>';
}
echo '</p>';
}
foreach ($arrQuestionId as $key=>$question) {
?>
<div class="queWrap">
//Each QuestionNo and QuestionContent
<p><?php echo htmlspecialchars($arrQuestionNo[$key]) . ": " . htmlspecialchars($arrQuestionContent[$key]); ?></p>
//Output each Individual Option
<p><?php echo ExpandOptionType(htmlspecialchars($arrOptionType[$key])); ?></p>
//Output each QuestionId text input per question
<p>Question Id:<input type='text' class='questionIds' name='questionids' value='<?php echo htmlspecialchars($arrQuestionId[$key]); ?>' /></p>
//Output each OptionType text input per question
<p>Option Type: <input type='text' class='optionType' name='optiontype' value='<?php echo htmlspecialchars($arrOptionType[$key]); ?>' /></p>
//Output each AnswerMarks per answer in each question
<p>Each Answer's Marks<input type='text' class='answermarks' name='answerMarks' value='<?php echo htmlspecialchars($arrAnswerMarks[$key]); ?>' /></p>
</div>
<?php
}
?>
</form>