-
Notifications
You must be signed in to change notification settings - Fork 0
/
phpquiz1.php
194 lines (141 loc) · 5.63 KB
/
phpquiz1.php
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<?php
include 'db.php';
session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>PHP quiz</title>
</head>
<body>
<center><H2><FONT COLOR="#000099">Quiz using PHP</FONT></H2></center>
<form name="quiz" action=quizaction.php method="POST">
<ul>
<font color="#CC0000"><b>Please click in the text fields below and enter the information requested.</b></FONT>
<ul><ul>
<li>First name:<input type="text" name="firstname" size="35"></li><br>
</ul></ul>
<hr>
<UL><B><FONT COLOR="#CC0000">Answer the questions below. Your individual responses will be kept confidential.<br>
For each item, select an option. When finished, click the "Done" button.</FONT></B></UL>
<!--
<UL>
1. PHP is a server-side scripting language.
<UL>
<INPUT TYPE="RADIO" NAME="question1" VALUE="answer1.1">True<BR>
<INPUT TYPE="RADIO" NAME="question1" VALUE="answer1.2">False<BR>
</UL></UL>
<HR>
<UL>
2. When you use the PHP script language in IU, what head do you type
in your script page?
<UL>
<INPUT TYPE="RADIO" NAME="question2"VALUE="answer2.1">#!/usr/local/bin/perl<BR>
<INPUT TYPE="RADIO" NAME="question2"VALUE="answer2.2">#!/usr/local/bin/php4<BR>
<INPUT TYPE="RADIO" NAME="question2" VALUE="answer2.3">#!/usr/local/bin/mysql<br>
</UL></UL>
-->
<?php
$db_select = mysqli_select_db($conn, "videojs");
if (!$db_select) {
die("Database selection failed: " . mysqli_error());
}
$get1= "SELECT list FROM `data` WHERE sess_id=1 ";
$result1 = $conn->query($get1);
$array_one = array();
while($row = $result1->fetch_assoc()) {
// echo $row["list"]. "<br>";
$array_one[] = $row;
// OR just echo the data:
// echo $row['list']."<br>"; // etc
}
//echo "array is this".$array_one[3]['list']."<br>";
///////////////////////////////////////////
$get2= "SELECT type FROM `questions`";
$result2 = $conn->query($get2);
$array_two = array();
while($row = $result2->fetch_assoc()) {
$array_two[] = $row;
}
//echo "array_two is this".$array_two[3]['type']."<br>";
/////////////////////////////////
$element=array_intersect(array_column($array_one, 'list'), array_column($array_two, 'type'));
$_SESSION['fin_element']= array_unique($element);
echo "list here"."<br>";
print_r($_SESSION['fin_element']);
/////////////////////////////
$sql = "SELECT * FROM questions WHERE `type` ='web'";
$result3 = $conn->query($sql);
$i=1;
if ($result3->num_rows > 0) {
// output data of each row
while($row = $result3->fetch_assoc()) {
echo "<br>";
echo "Q:" . $row["question_name"]. "<br>";
echo "<input type='radio' name='question".$i."' value='answer1'/><code>".$row["answer1"]."</code>". "<br>";
echo "<input type='radio' name='question".$i."' value='answer2'/><code>".$row["answer2"]."</code>". "<br>";
echo "<input type='radio' name='question".$i."' value='answer3'/><code>".$row["answer3"]."</code>". "<br>";
echo "<input type='radio' name='question".$i."' value='answer4'/><code>".$row["answer4"]."</code>". "<br>";
echo $i;
$i++;
}
} else {
echo "0 results";
}
$sql = "SELECT * FROM questions WHERE `type` IN ('".implode("','",$_SESSION['fin_element'])."')";
$result = $conn->query($sql);
$_SESSION['index']=6;
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<br>";
echo "Q:" . $row["question_name"]. "<br>";
echo "<input type='radio' name='question".$_SESSION['index']."' value='answer1'/><code>".$row["answer1"]."</code>". "<br>";
echo "<input type='radio' name='question".$_SESSION['index']."' value='answer2'/><code>".$row["answer2"]."</code>". "<br>";
echo "<input type='radio' name='question".$_SESSION['index']."' value='answer3'/><code>".$row["answer3"]."</code>". "<br>";
echo "<input type='radio' name='question".$_SESSION['index']."' value='answer4'/><code>".$row["answer4"]."</code>". "<br>";
echo $_SESSION['index'];
$_SESSION['index']++;
}
} else {
echo "0 results";
}
// passing tier value to quizaction.
echo "<input type='hidden' name='formvar' value=''>";
?>
<div id="timer">2:00</div>
<script type="text/javascript">
var timeoutHandle;
function countdown(minutes) {
var seconds = 60;
var mins = minutes
function tick() {
var counter = document.getElementById("timer");
var current_minutes = mins-1
seconds--;
counter.innerHTML =
current_minutes.toString() + ":" + (seconds < 10 ? "0" : "") + String(seconds);
// for sending data to the form...
document.quiz.formvar.value = seconds;
if(seconds <=0){
setTimeout('document.quiz.submit()',1);
}
if( seconds > 0 ) {
timeoutHandle=setTimeout(tick, 1000);
} else {
if(mins > 1){
// countdown(mins-1); never reach “00″ issue solved:Contributed by Victor Streithorst
setTimeout(function () { countdown(mins - 1); }, 1000);
}
}
}
tick();
}
countdown(1);
</script>
<INPUT TYPE="SUBMIT" VALUE="Done" >
<INPUT TYPE="RESET" VALUE="Clear all fields of this form">
</ul></ul>
</form>
</body>
</html>