我正在为我的网站进行测验..问题正在出现..我想用下一个按钮更改问题..只是显示一个问题,当我点击下一个按钮时,应该出现新问题,但不会出现.. < / p>
这是我的代码:
$project
这是我用来更改下一个问题的脚本
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<?php
$con=mysqli_connect("localhost","root","","studhelp");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
<?php
$cat=$_POST['cat']; // to get the category
$qus=qus_show($cat);
?>
<?php
/* .....function which will fetch data and display question ....*/
function qus_show($qus){
$con=mysqli_connect("localhost","root","","studhelp");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$resultQue=mysqli_query($con,"select * from questions where cat_id='$qus' order by rand() limit 4");
$no_of_rows=mysql_num_rows($resultQue);
?>
<div class="container">
<h2>Online test</h2>
<form method="post" action="answer.php">
<?php
$i=1; //question number
while($row=mysqli_fetch_assoc($resultQue)){
$row; ?>
<?php if($i==1){?>
<div id='question<?php echo $i;?>' class='cont'>
<p class='questions' id="qname<?php echo $i;?>"> <?php echo $i?>.<?php echo $row['question'];?></p>
<input type="radio" value="0" id='radio1_<?php echo $row['q_id'];?>' name='<?php echo $row['q_id'];?>'/><?php echo $row['opt-1'];?>
<br/>
<input type="radio" value="1" id='radio1_<?php echo $row['q_id'];?>' name='<?php echo $row['q_id'];?>'/><?php echo $row['opt-2'];?>
<br/>
<input type="radio" value="2" id='radio1_<?php echo $row['q_id'];?>' name='<?php echo $row['q_id'];?>'/><?php echo $row['opt-3'];?>
<br/>
<input type="radio" value="3" id='radio1_<?php echo $row['q_id'];?>' name='<?php echo $row['q_id'];?>'/><?php echo $row['opt-4'];?>
<br/>
<input type="radio" checked='checked' style='display:none' value="no_attempt" id='radio1_<?php echo $row['q_id'];?>' name='<?php echo $result['id'];?>'/>
<br/>
<button id='next<?php echo $i;?>' class='next btn btn-success' type='button'>Next</button>
</div>
<?php }elseif($i<1 || $i<$no_of_rows){?>
<div id='question<?php echo $i;?>' class='cont'>
<p class='questions' id="qname<?php echo $i;?>"><?php echo $i?>.<?php echo $result['question'];?></p>
<input type="radio" value="0" id='radio1_<?php echo $row['q_id'];?>' name='<?php echo $row['q_id'];?>'/><?php echo $row['opt-1'];?>
<br/>
<input type="radio" value="1" id='radio1_<?php echo $row['q_id'];?>' name='<?php echo $row['q_id'];?>'/><?php echo $row['opt-2'];?>
<br/>
<input type="radio" value="2" id='radio1_<?php echo $row['q_id'];?>' name='<?php echo $row['q_id'];?>'/><?php echo $row['opt-3'];?>
<br/>
<input type="radio" value="3" id='radio1_<?php echo $row['q_id'];?>' name='<?php echo $row['q_id'];?>'/><?php echo $row['opt-4'];?>
<br/>
<input type="radio" checked='checked' style='display:none' value="5" id='radio1_<?php echo $row['q_id'];?>' name='<?php echo $row['q_id'];?>'/>
<br/>
<button id='pre<?php echo $i;?>' class='previous btn btn-success' type='button'>Previous</button>
<button id='next<?php echo $i;?>' class='next btn btn-success' type='button' >Next</button>
</div>
<?php }elseif($i==$no_of_rows){?>
<div id='question<?php echo $i;?>' class='cont'>
<p class='questions' id="qname<?php echo $i;?>"><?php echo $i?>.<?php echo $result['question'];?></p>
<input type="radio" value="0" id='radio1_<?php echo $row['q_id'];?>' name='<?php echo $row['q_id'];?>'/><?php echo $row['opt-1'];?>
<br/>
<input type="radio" value="1" id='radio1_<?php echo $row['q_id'];?>' name='<?php echo $row['q_id'];?>'/><?php echo $row['opt-2'];?>
<br/>
<input type="radio" value="2" id='radio1_<?php echo $row['q_id'];?>' name='<?php echo $row['q_id'];?>'/><?php echo $row['opt-3'];?>
<br/>
<input type="radio" value="3" id='radio1_<?php echo$row['q_id'];?>' name='<?php echo $row['q_id'];?>'/><?php echo $row['opt-4'];?>
<br/>
<input type="radio" checked='checked' style='display:none' value="5" id='radio1_<?php echo $row['q_id'];?>' name='<?php echo $row['q_id'];?>'/>
<br/>
<button id='pre<?php echo $i;?>' class='previous btn btn-success' type='button'>Previous</button>
<button id='next<?php echo $i;?>' class='next btn btn-success' type='submit'>Finish</button>
</div>
<?php } $i++;} } ?>
</form>
</div>