我目前正在为我的网站构建一个多项选择测验模块。有一个包含 20 个问题的列表,只有登录的客户才能回答。
我有三张桌子:
表问题,带有字段 questions.id, questions.description
表选项,带有字段 options.id、options.questionid、options.trueorfalse
表 answers,带有字段 answers.id、answers.customerid、answers.questionid、answers.chosenoption
这些问题是通过 ajax 调用随机出现的,rand(),因此只显示客户未回答的问题。回答完所有问题后,将回显最终分数。
有人可以帮助我正确的 sql 语句应该运行 php 脚本以显示客户尚未回答的问题吗?
目前它似乎有效,但有时我必须提交两次相同的答案。实际上是第一次发送它,但是 ajax 调用显示了同样的问题。
这是我使用的sql语句...
SELECT * from questions
where not exists (
select answers.questionid from answers
where answers.questionid = questions.id
and answers.customerid = '".$customerid."' )
order by rand()
limit 1"
数据由 JQuery 帖子发送(效果很好)。在页面 quiz_ajax.php 内
<script type="text/javascript">
$(document).ready(function(){
$("#ajax-post-answer").submit(function(){
var str = $(this).serialize();
$.ajax({
type: "POST",
url: "answerpost.php",
data: str
});
callquiz();
return false;
});
});
</script>
页面内 quiz.php(主页面)
<script type="text/javascript">
function callquiz()
{
var newDate = new Date;
$.ajax({
method: 'POST',
url : 'quiz_ajax.php?' + newDate.getTime(),
dataType : 'text',
success: function (text) {
$('#updateMequiz').html(text); }
});
}
callquiz();
</script>
<div id="updateMequiz"></div>
所以函数 callquiz 应该用一个新问题刷新这个 div。我现在正在调查这个问题 24 小时,所以我很想知道我做错了什么。
提前致谢!!