我有一个带有 columns 的表subjects,questions,exam,question id
,我想从这个表中获取要显示的随机值。
对于我使用的每个问题:
$singleSQL = mysql_query("SELECT * FROM questions WHERE id='$question' ORDER BY rand() LIMIT 1");
对于每个主题:
$singleSQL = mysql_query("SELECT * FROM questions WHERE id='$question' AND subject='ayooooo' ORDER BY rand() LIMIT 1");
我想在页面加载时显示随机问题并且问下一个问题。
quiz.php?question='
我应该如何在这里使用它?
JavaScript:
function getQuestion() {
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("GET", "questions.php?question=" + <? php echo $question; ?> , true);
hr.send();
}
function x() {
var rads = document.getElementsByName("rads");
for (var i = 0; i < rads.length; i++) {
if (rads[i].checked) {
var val = rads[i].value;
return val;
}
}
}
function post_answer() {
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 url = 'quiz.php?question=<?php echo $next; ?>';
window.location = url;
}
}
p.send(vars);
document.getElementById("status")