我基本上是在准备一个考试门户,不同的科目都有不同的模拟考试,所有的东西都已经设置好了,但是出现的唯一问题是,当我们尝试对某个特定科目进行模拟考试而未解决一个问题时,这并不表示或在我的情况下显示红色,表示尝试,而绿色表示尝试下面的问题。还有其他方法可以显示未解决的问题,请提供帮助。.作为参考,我附上我的代码的片段,以供您参考。
<?php include "database.php"; ?>
<?php session_start(); ?>
<?php
//Check to see if score is set_error_handler
if (!isset($_SESSION['score'])){
$_SESSION['score'] = 0;
}
//Check if form was submitted
$selected_choice='';
if($_SERVER['REQUEST_METHOD']=='POST'){
$number = $_POST['number'];
$selected_choice = $_POST['choice'];
//Get total number of questions
$query="SELECT * FROM `trial`";
$results = $mysqli->query($query) or die($mysqli->error.__LINE__);
$total=$results->num_rows;
//Get correct choice
$q = "select * from `trial_choices` where question_number='".$number."' and is_correct=1";
$result = $mysqli->query($q) or die($mysqli->error.__LINE__);
$row = $result->fetch_assoc();
$correct_choice=$row['id'];
$next=$number+1;
//compare answer with result
if($correct_choice == $selected_choice){
$_SESSION['score']++;
}
if($number == $total){
header("Location: final.php");
exit();
} else {
header("Location: mocktrial.php?n=".$next."&score=".$_SESSION['score']);
}
}
?>
<?php
//Set question number
$number = $_GET['n'];
//Get total number of questions
$query = "select * from `trial`";
$results = $mysqli->query($query) or die($mysqli->error.__LINE__);
$total=$results->num_rows;
// Get Question
$query = "select * from `trial` where question_number = '".$number."'";
//Get result
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
$question = $result->fetch_assoc();
// Get Choices
$query = "select * from `trial_choices` where question_number = $number";
//Get results
$choices = $mysqli->query($query) or die($mysqli->error.__LINE__);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- Tell the browser to be responsive to screen width -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<!-- Favicon icon -->
<link rel="icon" type="image/png" sizes="16x16" href="images/favicon.png">
<title>Vidyapro</title>
<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/font-awesome.min.css" rel="stylesheet">
<![endif]-->
</head>
<body class="fix-header fix-sidebar" onload="setCountDown();">
<?php
$dateFormat = "d F Y -- g:i a";
$targetDate = time() + (10*60);//Change the 25 to however many minutes you want to countdown
$actualDate = time();
$secondsDiff = $targetDate - $actualDate;
$remainingDay = floor($secondsDiff/60/60/24);
$remainingHour = floor(($secondsDiff-($remainingDay*60*60*24))/60/60);
$remainingMinutes = floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))/60);
$remainingSeconds = floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))-($remainingMinutes*60));
$actualDateDisplay = date($dateFormat,$actualDate);
$targetDateDisplay = date($dateFormat,$targetDate);
?>
<div class="container-fluid" style=" background: #253253;">
<div class="row">
<div class="col-md-6">
<a href="index.php"><img src="img/photo_1530008755.png" class="img-responsive" style="width: 20%"></a>
</div>
<div class="col-md-6">
<p align="right"><br>
<i class="fa fa-sign-in" style="color: #fff"><a href="index.php" style="color: #fff"> Login</a></i>
<i class="fa fa-registered" style="color: #fff"><a href="registration.php" style="color: #fff"> Register</a></i>
</p>
</div>
</div>
</div><br>
<div class="container">
<h5 align="center">Welcome to Vidyapro! Answer the questions below. Your score will be displayed once all the questions have been answered. Good Luck!</h5><?php echo $selected_choice;?>
</div><br><br>
<div class="container">
<p align="center" style="font-size: 16px; color: #000">Maximum Marks: 20</p>
<center> <p align="center" style="font-size: 16px; color: #000;display: inline">Time Duration: <div id="remain" style="display: inline"><?php echo "$remainingHour hours, $remainingMinutes minutes, $remainingSeconds seconds";?></div></p></center>
Question <?php echo $number; ?> of <?php echo $total; ?><br>
<p class="question" style="font-size: 19px; color: #000">
<?php echo $question['question'] ?>
</p>
<form method="post" action="<?php htmlspecialchars($_SERVER['PHP_SELF'])?>">
<?php while($row=$choices->fetch_assoc()): ?>
<input name="choice" type="radio" value="<?=$row['id']?>">
<?php echo $row['choice']; ?>
<br>
<?php endwhile; ?>
<input type="hidden" name="number" value="<?=$number?>">
<?php
if(!($_GET['n']==20)){
?>
<input type="submit" value="Next" name="send" class="btn btn-info btn-sm" />
<?php }
if($_GET['n']==20){
?>
<input type="submit" value="Submit" name="send" class="btn btn-info btn-sm" />
<?php }?>
</form><br>
<?php
if($_GET['n']>1){
?>
<button onclick="goBack()" class="btn btn-primary btn-sm">Previous</button><br>
<?php } if(isset($_POST['choice'])){
for($i=1;$i<21;$i++){
$scr=$_POST['choice'];
if(empty($scr) && $number==$i){
?>
<a href="mocktrial.php?n=<?=$i?>" style='color:red'><?=$i?></a>
<?php
}
else{?>
<a href="mocktrial.php?n=<?=$i?>" style='color:success'><?=$i?></a>
<?php } }} ?>
</div>
<div class="container-fluid" style="margin-top: 6% ;background: #253253;">
<div class="row">
<div class="col-md-12">
<p align="center" style="color: #fff">© 2018. Vidyapro All Right Reserved. Powered By <a href="http://www.brandingheight.com/" target="_blank">Branding Height</a> c/o <a href="http://www.dezbridge.com/" target="_blank">Dezbridge Innovators Pvt Ltd</a></p>
</div>
</div>
</div>
<script>
function goBack() {
window.history.back();
}
</script>
<script type="text/javascript">
var days = <?php echo $remainingDay; ?>
var hours = <?php echo $remainingHour; ?>
var minutes = <?php echo $remainingMinutes; ?>
var seconds = <?php echo $remainingSeconds; ?>
function setCountDown ()
{
seconds--;
if (seconds < 0){
minutes--;
seconds = 59
}
if (minutes < 0){
hours--;
minutes = 59
}
if (hours < 0){
days--;
hours = 23
}
document.getElementById("remain").innerHTML = +hours+" hours "+minutes+" minutes "+seconds+" seconds";
SD=window.setTimeout( "setCountDown()", 1000 );
if (minutes == '00' && seconds == '00') { seconds = "00"; window.clearTimeout(SD);
//window.alert("Time is up. Press OK to continue."); // change timeout message as required
window.location = "final.php" // Add your redirect url
}
}
</script>
</body>
</html>
Run code snippetExpand snippet
javascript php html css