-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquestion.php
80 lines (69 loc) · 2.11 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
<?php session_start(); ?>
<?php include 'database.php'?>
<?php
//Set question number
$number = (int)$_GET['n'];
/*
* Get total questions
*/
$query = "SELECT * FROM questions";
// Get result
$results = $mysqli->query($query) or die($mysqli->error . __LINE__);
$total = $results->num_rows;
/*
* ------------------Get Question------------------------
*/
$query = "SELECT * FROM questions
WHERE question_number = $number";
//Get Result
$result = $mysqli->query($query) or die($mysqli->error . __LINE__);
//Assign result to variable
$question = $result->fetch_assoc();
/*
* --------------------Get Choices------------------------
*/
$query = "SELECT * FROM choices
WHERE question_number = $number";
//Get Choices
$choices = $mysqli->query($query) or die($mysqli->error . __LINE__);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>PHP Quizzer</title>
<link rel="stylesheet" href="css/style.css" type="text/css">
</head>
<body>
<header>
<div class="container">
<h1>PHP Quizzer</h1>
</div>
</header>
<main>
<div class="container">
<div class="current">Question <?php echo $question['question_number'] ?> of <?php echo $total ?></div>
<p class="question">
<?php echo $question['text']; ?>
</p>
<form method="post" action="process.php">
<ul class="choices">
<?php while($row = $choices->fetch_assoc()) : ?>
<?php if ($number == 1) {
$_SESSION['score'] = 0;
} ?>
<li><input name="choice" type="radio" value="<?php echo $row['id']; ?>"><?php echo $row['text'];?></li>
<?php endwhile; ?>
</ul>
<input type="submit" value="Submit">
<input type="hidden" name="number" value="<?php echo $number; ?>">
</form>
</div>
</main>
<footer>
<div class="container">
Copyright © 2020, PHP Quizzer
</div>
</footer>
</body>
</html>