<?php
$singleSQL = mysql_query("SELECT * FROM questions WHERE subject_id='$subject' AND question_id='$question'");
$row = mysql_fetch_array($singleSQL);
$thisQuestion = $row['question'];
$type = $row['type'];
$question_id = $row['question_id'];
$q = '<h2>'.$thisQuestion.'</h2>';
$sql2 = mysql_query("SELECT * FROM answers WHERE question_id='$question' ORDER BY rand()");
while($row2 = mysql_fetch_array($sql2)){
$answer = $row2['answer'];
$correct = $row2['correct'];
$answers .= '<label style="cursor:pointer;"><input type="checkbox" name="rads" value="'.$correct.'">'.$answer.'</label>
<input type="hidden" id="qid" value="'.$id.'" name="qid"><br /><br />
';
}
$output = ''.$q.','.$answers.',<span id="btnSpan"><button onclick="post_answer()">Atsakyti</button></span>';
echo $output;
?>
不对所选主题发布问题。在数据库中找不到问题,因为问题具有不同的主题ID,并且它不是任何顺序。
var p = new XMLHttpRequest();
var id = document.getElementById('qid').value;
var url = "userAnswers.php";
var vars = "qid=" + id + "&radio=" + x();
p.open("POST", url, true);
p.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
p.onreadystatechange = function() {
if (p.readyState == 4 && p.status == 200) {
document.getElementById("status").innerHTML = '';
var hr = new XMLHttpRequest();
hr.onreadystatechange = function() {
if (hr.readyState == 4 && hr.status == 200) {
var response = hr.responseText.split("|");
if (response[0] == "finished") {
document.getElementById('status').innerHTML = response[1];
}
var nums = hr.responseText.split(",");
document.getElementById('question').innerHTML = nums[0];
document.getElementById('answers').innerHTML = nums[1];
document.getElementById('answers').innerHTML += nums[2];
}
}
hr.open("post", "questions.php", true);
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
hr.send("subject=<?php echo $subject; ?>&question=<?php echo $next; ?>");
}
}
p.send(vars);
}
这是按钮触发的功能
答案 0 :(得分:0)
检查您的查询。 $question_id
失踪。
$sql2 = mysql_query("SELECT * FROM answers WHERE question_id='$question_id' ORDER BY rand()");