javascript - 在 html 的测验网站中一次显示一个问题
问题描述
我做了一个测验网站,其中显示了一个问题和 4 个带有单选按钮的选项。问题是从数据库中获取的。但是所有的问题都同时出现。我想在用户单击选项时一次显示一个问题。在他单击选项后不久,当前问题应该消失并显示下一个问题。我尝试了很多使用javascript的方法,但没有任何效果。谁能帮我。这是我的html代码
<div class="services">
<div class="container">
<?php $response=mysql_query("select * from questions");?>
<form method='post' id='quiz_form'>
<?php while($result=mysql_fetch_array($response)){ ?>
<div id="question_<?php echo $result['id'];?>" class='question'> <!--check the class for plurals if error occurs-->
<h2 id="question_<?php echo $result['id'];?>"><?php echo $result['id'].".".$result['question_name'];?></h2>
<div class='align'>
<input type="radio" value="1" id='radio1_<?php echo $result['id'];?>' name='<?php echo $result['id'];?>'>
<label id='ans1_<?php echo $result['id'];?>' for='1'><?php echo $result['answer1'];?></label>
<br/>
<input type="radio" value="2" id='radio2_<?php echo $result['id'];?>' name='<?php echo $result['id'];?>'>
<label id='ans2_<?php echo $result['id'];?>' for='1'><?php echo $result['answer2'];?></label>
<br/>
<input type="radio" value="3" id='radio3_<?php echo $result['id'];?>' name='<?php echo $result['id'];?>'>
<label id='ans3_<?php echo $result['id'];?>' for='1'><?php echo $result['answer3'];?></label>
<br/>
<input type="radio" value="4" id='radio4_<?php echo $result['id'];?>' name='<?php echo $result['id'];?>'>
<label id='ans4_<?php echo $result['id'];?>' for='1'><?php echo $result['answer4'];?></label>
<input type="radio" checked='checked' value="5" style='display:none' id='radio4_<?php echo $result['id'];?>' name='<?php echo $result['id'];?>'>
</div>
<br/>
<input type="button" id='next<?php echo $result['id'];?>' value='Next!' name='question' class='butt'/>
</div>
<?php }?>
</form>
</div>
</div>
解决方案
那是因为您正在使用select * from questions
,这将获取问题数据库中的所有内容,您将要做的是一次请求一个问题select * from questions LIMIT 0, 1 // index_from, amount
,然后下一次将您的限制增加一个LIMIT 1, 1
推荐阅读
- stm32 - 将 BMP280 传感器与 stm32l4 连接
- javascript - 渲染内无限循环中的setState
- python - 如何根据您的需要在 ODOO 上设置电子邮件模板频率?
- java - 代理身份验证 selenium java
- c# - Unity CheckSphere 或 OverlapSphere
- google-signin - JavaScript API 启动登录流程以使用 Google 库进行新登录
- c++ - 禁止警告消息“此项目包含可能不安全的附件”Outlook 附件外发邮件
- c# - 在本地运行测试时忽略 OneTimeSetup 和 TearDown
- lattice-diamond - Lattice Diamond Synthesis 退出并出现错误代码 999
- cisco - 带有 tcpdump 的 CDP - 如何区分“主干”或“访问”端口?