-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviewQuestions.php
102 lines (91 loc) · 3.33 KB
/
viewQuestions.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
<?php
session_start();
if (!isset($_SESSION['user_email'])) {
header('Location: Home.php');
exit;
}
// Include the necessary database operations
include "engineDB.php";
$store_db = new EngineDB();
$store_db->connect();
// Retrieve all questions from the database
$query = "SELECT id_question, question FROM entity_question";
$result = $store_db->getDb()->query($query);
$questions = [];
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$questions[] = $row;
}
}
$answerQuery = "SELECT id_answer, answer FROM entity_answer";
$answerResult = $store_db->getDb()->query($answerQuery);
$answers = [];
if ($answerResult->num_rows > 0) {
while($row = $answerResult->fetch_assoc()) {
$answers[] = $row;
}
}
$crossR = "SELECT id_question, id_answer FROM xref_question_answer";
$crossRefResult = $store_db->getDb()->query($crossR);
$crossRefs = [];
if ($crossRefResult->num_rows > 0) {
while($row = $crossRefResult->fetch_assoc()) {
$crossRefs[] = $row;
}
}
$store_db->disconnect();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>View Questions</title>
<link rel="stylesheet" href="css/admin-styles.css">
</head>
<body>
<div class="sidenav">
<form action="Admin.php" method="post">
<button type="submit" name="action" value="view_users">View Users</button>
<button type="submit" name="action" value="view_surveys">View Surveys</button>
<button type="submit" name="action" value="view_survey_results">View User-Survey Results</button>
<button type="submit" name="action" value="view_questions">View Questions</button>
<button type="submit" name="action" value="exit">Exit</button>
</form>
</div>
<div class="content">
<h1>All Questions</h1>
<?php if (empty($questions)): ?>
<p>No questions found.</p>
<?php else: ?>
<table>
<thead>
<tr>
<th>Question</th>
<th>Choices</th>
</tr>
</thead>
<tbody>
<?php foreach ($questions as $question): ?>
<tr>
<td><?php echo htmlspecialchars($question['question']); ?></td>
<td>
<ul>
<?php foreach ($crossRefs as $crossRef): ?>
<?php if ($crossRef['id_question'] == $question['id_question']): ?>
<?php foreach ($answers as $answer): ?>
<?php if ($crossRef['id_answer'] == $answer['id_answer']): ?>
<li><?php echo htmlspecialchars($answer['answer']); ?></li>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
<?php endforeach; ?>
</ul>
</tr>
<?php endforeach; ?>
<br><br>
</tbody>
</table>
<?php endif; ?>
</div>
</body>
</html>