本文给大家介绍如何使用jQuery+PHP+MySQL来实现在线测试题,包括动态读取题目,答题完毕后台评分,并返回答题结果。
读取答题列表:$sql = "select * from quiz order by id asc"; <br>
$query = mysql_query($sql); <br>
while ($row = mysql_fetch_array($query)) { <br>
$answers = explode('###', $row['answer']); <br>
$arr[] = array( <br>
'question' => $row['id'] . '、' . $row['question'], <br>
'answers' => $answers <br>
); <br>
} <br>
$json = json_encode($arr);
我们在#quiz-container生成答题列表:<div></div>
quiz插件调用:$(function(){ <br>
$('#quiz-container').jquizzy({ <br>
questions: <?php echo $json;?>, //试题信息 <br>
sendResultsURL: 'data.php' //结果处理地址 <br>
}); <br>
});
答题演示地址:http://www.sucaihuo.com/php/113.html
AD:真正免费,域名+虚机+企业邮箱=0元