-
Notifications
You must be signed in to change notification settings - Fork 0
/
question.php
73 lines (65 loc) · 2.06 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
<?php include 'database.php'; ?>
<?php
//Set question number
$qno = (int) $_GET['n'];
/*
** BAD PRACTICE ! Getting total no. of questions
*/
$q_count = $mysqli->query("SELECT * FROM `questions`")->num_rows or die ($mysqli->error.__LINE__);
/*
** Get the Question
*/
$query1 = "SELECT * FROM `questions` WHERE question_number = $qno";
//Get Result
$res1 = $mysqli->query($query1) or die($mysqli->error.__LINE__);
$question = $res1->fetch_assoc();
/*
** Get the Choices
*/
$query2 = "SELECT * FROM `choices` WHERE question_number = $qno";
//Get Result
$res2 = $mysqli->query($query2) or die($mysqli->error.__LINE__);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="css/style.css">
<title>PHP Quizzer</title>
</head>
<body>
<header>
<div class="container">
<h1>PHP Quizzer</h1>
</div>
</header>
<main>
<div class="container">
<div class="current">
Question <?php echo $qno ?> of <?php echo $q_count ?>
</div>
<p class="question">
<?php echo $question['text']; ?>
</p>
<form action="process.php" method="POST">
<ul>
<?php while ($choice = $res2->fetch_assoc()) : ?>
<li><input type="radio" name="choice" value="<?php echo $choice['id']; ?>">
<?php echo htmlspecialchars($choice['text']); ?>
</li>
<?php endwhile; ?>
</ul>
<input type="hidden" name="qno" value="<?php echo $qno; ?>">
<input type="submit" value="Submit">
</form>
</div>
</main>
<footer>
<div class="container">
Copyright © 2019, PHP Quizzer
</div>
</footer>
</body>
</html>