首页 > 解决方案 > 在 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>

标签: javascriptphpjqueryhtmlmysql

解决方案


那是因为您正在使用select * from questions,这将获取问题数据库中的所有内容,您将要做的是一次请求一个问题select * from questions LIMIT 0, 1 // index_from, amount,然后下一次将您的限制增加一个LIMIT 1, 1


推荐阅读