What's new

Gusto ko sana magtanong kaso baka walang sumagot

m0stwanted143

Eternal Poster
Joined
Feb 8, 2016
Posts
925
Reaction
189
Points
310
Online examination web based
Php and javascript

Ayaw ma lagay yung question and option pero may countdown timer sya di lang na didisplay
 
load_questions.php

<?php
session_start();
include "../config/db_connect.php";
$question_no="";
$question="";
$opt1="";
$opt2="";
$opt3="";
$opt4="";
$answer="";
$count=0;
$ans="";

$queno =$_GET['questionno'];
if(isset($_SESSION["answer"][$queno]))
{
$ans=$_SESSION["answer"][$queno];
}

$res=mysqli_query($conn, "SELECT * from exam_questions
where examname= 'quizko'");
$count = mysqli_num_rows($res);
if($count==0)
{
echo "over";
}
else
{
while($row=mysqli_fetch_array($res))
{
$question_no=$row["$queno"];
$question=$row["question"];
$opt1=$row["opt1"];
$opt2=$row["op2"];
$opt3=$row["opt3"];
$opt4=$row["opt4"];

}
?>
<br>
<table>
<tr>
<td style="font-weight: bold; fon-size: 16px; padding-left: 5px" colspan="2">
<?php echo "".$queno.".) ".$question; ?>
</td>
</tr>
</table>
<table>
<tr>
<td>
<input style="radio" name="r1" id="r1" value="<?php echo $opt1; ?>">
<?php
if ($answer==$opt1)
{
echo "checked";
}
?>
</td>
<td style="padding-left: 10px">
<?php
if (strpos($opt1,'images/')!=false)
{
?>
<img scr="admin/<?php echo $opt1;?>" height="30px" width="30">
<?php
}
else
{
echo $opt2;
}
?>
</td>
</tr>

</table>

<?php
}
?>
 
load_total_que.php

<?php
session_start();
include("../config/db_connect.php");
$total_que = 0;
$res1=mysqli_query($conn, "SELECT * FROM exam_questions WHERE examname = '$_SESSION[examname]'");
$total_que= mysqli_num_rows($res1);
echo $total_que;

?>
 
dashboard.php

<?php
session_start();
include("header.php");
?>
<!-- /header -->

<div class="row" style="...">

<div class="col-lg-6 col-lg-push-3" style="...">

<br>

<br>
<div class="row"class="col-lg-3 col-lg-push-10">

<div id="current_cue" style="float:left">0</div>
<div style="float:left">/</div>
<div id="total_cue" style="float:left">0</div>
</div>

<div class="row" style="margin-top: 30px">
<div class="row">
<div class="col-lg-10 col-lg-push-1" style="min-height: 300px; background-color: white;" id="load_questions">

</div>
</div>
</div>
<div class="row" style="margin-top:10px">
<div class="col-lg-6 col-lg-push-3" style="min-height: 50px">
<div class="col-lg-12 text-center">
<input type="button" class="btn btn-warning" value="Previous" onclick="load_previous();">&nbsp;
<input type="button" class="btn btn-success" value="Next" onclick="load_next();">

</div>
</div>
</div>

</div>
</div>
</div>
<script type="text/javascript">
function load_total_que()
{
var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
document.getElementById("total_que").innerHTML=xmlhttp.responseText;
}
};
xmlhttp.open("GET","forajax/load_total_que.php",true);
xmlhttp.send(null);
}
var questionno = "1";
load_questions(questionno);
function load_questions(questionno)
{
document.getElementById("current_que").innerHTML=questionno;
var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
if (xmlhttp.responseText=="over")
{
window.location="result.php";
}
else
{
document.getElementById("load_questions").innerHTML = xmlhttp.responseText;
load_total_que();
}
}
};
xmlhttp.open("GET","forajax/load_questions.php?questionno="+ questionno, true);
xmlhttp.send(null);
}
function load_previous()
{
if(questionno=="1")
{
load_questions(questionno);
}
else
{
questionno = eval(questionno)-1;
load_questions(questionno);
}
}
function load_next()
{
questionno=eval(questionno)+1;
load_questions(questionno);
}
</script>

<script src="vendors/jquery/dist/jquery.min.js"></script>
<script src="vendors/popper.js/dist/umd/popper.min.js"></script>
<script src="vendors/jquery-validation/dist/jquery.validate.min.js"></script>
<script src="vendors/jquery-validation-unobtrusive/dist/jquery.validate.unobtrusive.min.js"></script>
<script src="vendors/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="assets/js/main.js"></script>
</body>
</html>
 
Yung problem is di po ma display yung question at option gawa sa java di ata nag pa function pati ung number of question over to wala din di na didisplay..
 
Code:
<?php
session_start();
include("header.php");
?>
<!-- /header -->

<div class="row" style="...">

<div class="col-lg-6 col-lg-push-3" style="...">

<br>

<br>
<div class="row"class="col-lg-3 col-lg-push-10">

<div id="current_cue" style="float:left">0</div>
<div style="float:left">/</div>
<div id="total_cue" style="float:left">0</div>
</div>

<div class="row" style="margin-top: 30px">
<div class="row">
<div class="col-lg-10 col-lg-push-1" style="min-height: 300px; background-color: white;" id="load_questions">

</div>
</div>
</div>
<div class="row" style="margin-top:10px">
<div class="col-lg-6 col-lg-push-3" style="min-height: 50px">
<div class="col-lg-12 text-center">
<input type="button" class="btn btn-warning" value="Previous" onclick="load_previous();">&nbsp;
<input type="button" class="btn btn-success" value="Next" onclick="load_next();">

</div>
</div>
</div>

</div>
</div>
</div>
<script type="text/javascript">
function load_total_que()
{
var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
document.getElementById("total_que").innerHTML=xmlhttp.responseText;
}
};
xmlhttp.open("GET","forajax/load_total_que.php",true);
xmlhttp.send(null);
}
var questionno = "1";
load_questions(questionno);
function load_questions(questionno)
{
document.getElementById("current_que").innerHTML=questionno;
var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
if (xmlhttp.responseText=="over")
{
window.location="result.php";
}
else
{
document.getElementById("load_questions").innerHTML = xmlhttp.responseText;
load_total_que();
}
}
};
xmlhttp.open("GET","forajax/load_questions.php?questionno="+ questionno, true);
xmlhttp.send(null);
}
function load_previous()
{
if(questionno=="1")
{
load_questions(questionno);
}
else
{
questionno = eval(questionno)-1;
load_questions(questionno);
}
}
function load_next()
{
questionno=eval(questionno)+1;
load_questions(questionno);
}
</script>

<script src="vendors/jquery/dist/jquery.min.js"></script>
<script src="vendors/popper.js/dist/umd/popper.min.js"></script>
<script src="vendors/jquery-validation/dist/jquery.validate.min.js"></script>
<script src="vendors/jquery-validation-unobtrusive/dist/jquery.validate.unobtrusive.min.js"></script>
<script src="vendors/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="assets/js/main.js"></script>
</body>
</html>
 
load_total_que.php
Code:
<?php
session_start();
include("../config/db_connect.php");
$total_que = 0;
$res1=mysqli_query($conn, "SELECT * FROM exam_questions WHERE examname = '$_SESSION[examname]'");
$total_que= mysqli_num_rows($res1);
echo $total_que;

?>
 
load_questions.php
Code:
<?php
session_start();
include "../config/db_connect.php";
$question_no="";
$question="";
$opt1="";
$opt2="";
$opt3="";
$opt4="";
$answer="";
$count=0;
$ans="";

$queno =$_GET['questionno'];
if(isset($_SESSION["answer"][$queno]))
{
$ans=$_SESSION["answer"][$queno];
}

$res=mysqli_query($conn, "SELECT * from exam_questions
where examname= 'quizko'");
$count = mysqli_num_rows($res);
if($count==0)
{
echo "over";
}
else
{
while($row=mysqli_fetch_array($res))
{
$question_no=$row["$queno"];
$question=$row["question"];
$opt1=$row["opt1"];
$opt2=$row["op2"];
$opt3=$row["opt3"];
$opt4=$row["opt4"];

}
?>
<br>
<table>
<tr>
<td style="font-weight: bold; fon-size: 16px; padding-left: 5px" colspan="2">
<?php echo "".$queno.".) ".$question; ?>
</td>
</tr>
</table>
<table>
<tr>
<td>
<input style="radio" name="r1" id="r1" value="<?php echo $opt1; ?>">
<?php
if ($answer==$opt1)
{
echo "checked";
}
?>
</td>
<td style="padding-left: 10px">
<?php
if (strpos($opt1,'images/')!=false)
{
?>
<img scr="admin/<?php echo $opt1;?>" height="30px" width="30">
<?php
}
else
{
echo $opt2;
}
?>
</td>
</tr>

</table>

<?php
}
?>
 
so ang gusto mong gawin pag click nya ng btn mag change ng question? tama ba?

gamit ka ng ajax para mag load ng question then append mo nalang

bale gamit ka ng json sa pag response ng server para madali
 
[XX='PHC_Jayvee, c: 1089257, m: 1155000'][/XX] ajax at json? display palang ng quesiton galing mysql di lumalabas $session name dapat lalabas at yung mga option sa mysql
 
[XX='m0stwanted143, c: 1089413, m: 462587'][/XX] so yung problem ay hindi mo ma echo yung row?

So bakit mo pa pinaste buong code?

Btw use while($data = mysql_fetch_assoc($res))
 
Back
Top