-
Notifications
You must be signed in to change notification settings - Fork 1
/
question.php
138 lines (105 loc) · 4.51 KB
/
question.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
<?php require_once 'header.php'; ?>
<?php
if (isset($_GET['test_id'])) {
$test_id = $_GET['test_id'];
//echo $test_id;
$statement = $db->prepare("SELECT * FROM tbl_test WHERE id = ?");
$statement->execute(array($test_id));
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
foreach($result as $row)
{
$test_name = $row['test_name'];
$max_number_of_question = $row['max_question'];
}
}else{
header("location: index.php");
}
if(isset($_POST['formans']))
{
$solution = $_POST['solution'];
$correct = 0;
(isset($_POST['ans1']) ? ($_POST['ans1'] == $solution[0]) ? $correct = $correct+1 : '' : '');
(isset($_POST['ans2']) ? ($_POST['ans2'] == $solution[1]) ? $correct = $correct+1 : '': '');
(isset($_POST['ans3']) ? ($_POST['ans3'] == $solution[2]) ? $correct = $correct+1 : '': '');
(isset($_POST['ans4']) ? ($_POST['ans4'] == $solution[3]) ? $correct = $correct+1 : '': '');
(isset($_POST['ans5']) ? ($_POST['ans5'] == $solution[4]) ? $correct = $correct+1 : '': '');
(isset($_POST['ans6']) ? ($_POST['ans6'] == $solution[5]) ? $correct = $correct+1 : '': '');
(isset($_POST['ans7']) ? ($_POST['ans7'] == $solution[6]) ? $correct = $correct+1 : '': '');
(isset($_POST['ans8']) ? ($_POST['ans8'] == $solution[7]) ? $correct = $correct+1 : '': '');
(isset($_POST['ans9']) ? ($_POST['ans9'] == $solution[8]) ? $correct = $correct+1 : '': '');
(isset($_POST['ans10']) ? ($_POST['ans10'] == $solution[9]) ? $correct = $correct+1 : '': '');
(isset($_POST['ans11']) ? ($_POST['ans11'] == $solution[10]) ? $correct = $correct+1 : '': '');
(isset($_POST['ans12']) ? ($_POST['ans12'] == $solution[11]) ? $correct = $correct+1 : '': '');
(isset($_POST['ans13']) ? ($_POST['ans13'] == $solution[12]) ? $correct = $correct+1 : '': '');
(isset($_POST['ans14']) ? ($_POST['ans14'] == $solution[13]) ? $correct = $correct+1 : '': '');
(isset($_POST['ans15']) ? ($_POST['ans15'] == $solution[14]) ? $correct = $correct+1 : '': '');
(isset($_POST['ans16']) ? ($_POST['ans16'] == $solution[15]) ? $correct = $correct+1 : '': '');
(isset($_POST['ans17']) ? ($_POST['ans17'] == $solution[16]) ? $correct = $correct+1 : '': '');
(isset($_POST['ans18']) ? ($_POST['ans18'] == $solution[17]) ? $correct = $correct+1 : '': '');
(isset($_POST['ans19']) ? ($_POST['ans19'] == $solution[18]) ? $correct = $correct+1 : '': '');
(isset($_POST['ans20']) ? ($_POST['ans20'] == $solution[19]) ? $correct = $correct+1 : '': '');
(isset($_POST['ans21']) ? ($_POST['ans21'] == $solution[20]) ? $correct = $correct+1 : '': '');
(isset($_POST['ans22']) ? ($_POST['ans22'] == $solution[21]) ? $correct = $correct+1 : '': '');
//enter upto 50 ans
?>
<div class="panel panel-primary">
<div class="panel-heading">
<h2>Result Information</h2>
</div>
<div class="panel-body">
<h3>Correct Answer - <mark><?= $correct ?></mark></h3>
<h3>Incorrect Answer - <mark><?= count($solution) - $correct ?></mark></h3>
</div>
</div>
<?php }else{ ?>
<h1 class="page-header">Question</h1>
<?php
?>
<form action="" method="POST">
<table> <?php
if($test_id != "")
{
$i = 0;
$statement = $db->prepare("SELECT id, question_title, option_1, option_2, option_3, option_4, correct_option FROM tbl_question WHERE test_id=? ORDER BY RAND() LIMIT $max_number_of_question");
$statement->execute(array($test_id));
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $row)
{
//$solution[] = $row['solution'];
$i++;
?>
<tr>
<td>Question No.(<?php echo $i; ?>) :</td>
<td><?php echo $row['question_title']; ?></td>
</tr>
<tr>
<td>Option :</td>
<td>
<input type="radio" name="ans<?= $i ?>" value="1"><?php echo $row['option_1']; ?><br>
<input type="radio" name="ans<?= $i ?>" value="2"><?php echo $row['option_2']; ?><br>
<input type="radio" name="ans<?= $i ?>" value="3"><?php echo $row['option_3']; ?> <br>
<input type="radio" name="ans<?= $i ?>" value="4"><?php echo $row['option_4']; ?>
</td>
<input type="hidden" name="solution[]" value="<?php echo $row['correct_option']; ?>">
</tr>
<?php }
}
?>
<?php
if ($statement->rowCount() == 0) { ?>
<div class="alert alert-success">
<strong>Sorry !! </strong> There is no question has added yet there....
</div>
<?php }else{ ?>
<tr><td> </td>
</tr>
<tr>
<td>Submit your answer.</td>
<td><input type="submit" name="formans" value="Check Result"></td>
</tr>
<?php } ?>
</table>
</form>
<?php } ?>
<!-- end index -->
<?php require_once 'footer.php'; ?>