-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquiz.php
More file actions
162 lines (133 loc) · 4.59 KB
/
Copy pathquiz.php
File metadata and controls
162 lines (133 loc) · 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
$std=$_POST["standard"];
$sub=$_POST["subject"];
$chap=$_POST["chapter"];
$level=$_POST["level"];
$con=mysqli_connect("localhost","root","");
mysqli_select_db($con,"tictechtoe");
$s=mysqli_query($con,"select q.Question,q.OpA,q.OpB,q.OpC,q.OpD from questions as q where q.Subject='$sub'
and q.Std=$std and q.Chapter=$chap and q.Level=$level");
$a=mysqli_fetch_array($s,MYSQLI_ASSOC);
if($level==1 or $level==2 )
{
$x=2;
$rn=mt_rand(1,$x);
$s=mysqli_query($con,"select q.Question,q.OpA,q.OpB,q.OpC,q.OpD,q.ans,q.Level from questions as q where q.Subject='$sub'
and q.Std=$std and q.Chapter=$chap and q.Level=$level");
$a=mysqli_fetch_array($s,MYSQLI_ASSOC);
}
elseif($level==3)
{
$x=1;
$rn=mt_rand(1,$x);
$s=mysqli_query($con,"select q.Question,q.OpA,q.OpB,q.OpC,q.OpD,q.ans,q.Level from questions as q where q.Subject='$sub'
and q.Std=$std and q.Chapter=$chap and q.Level=$level");
$a=mysqli_fetch_array($s,MYSQLI_ASSOC);
}
else
{
$level=mt_rand(1,3);
if($level==1||$level==2)
$x=2;
else
$x=1;
$rn=mt_rand(1,$x);
$s=mysqli_query($con,"select q.Question,q.OpA,q.OpB,q.OpC,q.OpD,q.ans,q.Level from questions as q where q.Subject='$sub'
and q.Std=$std and q.Chapter=$chap and q.Level=$level");
$a=mysqli_fetch_array($s,MYSQLI_ASSOC);
}
?>
<script>
var questions = [];
var curr_que = 0;
var que1 = {
stat:<?php echo $a["Question"] ?>,
op1: <?php echo $a["OpA"] ?>,
op2: <?php echo $a["OpB"] ?>,
op3: <?php echo $a["OpC"] ?>,
op4: <?php echo $a["OpD"] ?>,
correct: <?php echo $a["ans"] ?>
}
var que2 = {
stat:<?php echo $a["Question"] ?>,
op1: <?php echo $a["OpA"] ?>,
op2: <?php echo $a["OpB"] ?>,
op3: <?php echo $a["OpC"] ?>,
op4: <?php echo $a["OpD"] ?>,
correct: <?php echo $a["ans"] ?>
}
var que3 = {
stat:<?php echo $a["Question"] ?>,
op1: <?php echo $a["OpA"] ?>,
op2: <?php echo $a["OpB"] ?>,
op3: <?php echo $a["OpC"] ?>,
op4: <?php echo $a["OpD"] ?>,
correct: <?php echo $a["ans"] ?>
}
var que4 = {
stat:<?php echo $a["Question"] ?>,
op1: <?php echo $a["OpA"] ?>,
op2: <?php echo $a["OpB"] ?>,
op3: <?php echo $a["OpC"] ?>,
op4: <?php echo $a["OpD"] ?>,
correct: <?php echo $a["ans"] ?>
}
var que5 = {
stat:<?php echo $a["Question"] ?>,
op1: <?php echo $a["OpA"] ?>,
op2: <?php echo $a["OpB"] ?>,
op3: <?php echo $a["OpC"] ?>,
op4: <?php echo $a["OpD"] ?>,
correct: <?php echo $a["ans"] ?>
}
console.dir(que5);
questions.push(que1);
questions.push(que2);
questions.push(que3);
questions.push(que4);
questions.push(que5);
var lis = document.querySelectorAll("li");
var que_stat = document.querySelector("#que_stat");
var opt1 = document.querySelector("#opt1");
var opt2 = document.querySelector("#opt2");
var opt3 = document.querySelector("#opt3");
var opt4 = document.querySelector("#opt4");
lis.forEach(function(item){
item.addEventListener("click", function(){
if(this.classList.contains("disabled")) return;
document.querySelector("button").disabled = false;
var num = Number(this.id)/10 - 1;
curr_que = num;
que_stat.innerText = questions[num].stat;
opt1.innerText = questions[num].op1;
opt2.innerText = questions[num].op2;
opt3.innerText = questions[num].op3;
opt4.innerText = questions[num].op4;
opt1.parentElement.classList.remove("correct");
opt2.parentElement.classList.remove("correct");
opt3.parentElement.classList.remove("correct");
opt4.parentElement.classList.remove("correct");
opt1.parentElement.classList.remove("incorrect");
opt2.parentElement.classList.remove("incorrect");
opt3.parentElement.classList.remove("incorrect");
opt4.parentElement.classList.remove("incorrect");
});
});
var btn = document.querySelector("button");
btn.addEventListener("click", function(){
var correctAns = questions[curr_que].correct;
var userChoice = document.querySelector("input:checked");
var userAns = userChoice.value;
var comment = document.querySelector("#comment");
this.disabled = true;
if(correctAns === userAns){
comment.innerText = "Correct Answer!";
userChoice.parentElement.classList.add("correct");
} else {
comment.innerText = "Wrong Answer!";
userChoice.parentElement.classList.add("incorrect");
document.getElementById(correctAns).classList.add("correct");
}
document.getElementById((curr_que+1)*10).classList.add("disabled");
});
</script>