-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetting2.php
More file actions
59 lines (33 loc) · 1.19 KB
/
setting2.php
File metadata and controls
59 lines (33 loc) · 1.19 KB
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
<?php
//Connect to Db and fetch questions
require_once('db_conn.php');
//Create a query to fetch all the questions
$query = "select * from quiz2";
//Run the query
$query_result = $dbc->query($query);
//Count the number of returned items from the database
$num_questions_returned = $query_result->num_rows;
if ($num_questions_returned < 1){
echo "There is no question in the database";
exit();}
//Create an array to hold all the returned questions
$questionsArray = array();
//Add all the questions from the result to the questions array
while ($row = $query_result->fetch_assoc()){
$questionsArray[] = $row;
}
//Create an array of Correct answers
$correctAnswerArray = array();
foreach($questionsArray as $question){
$correctAnswerArray[$question['questionid']] = $question['answer'];
}
//Build the questions array from query result
$questions = array();
foreach($questionsArray as $question) {
$questions[$question['questionid']] = $question['name'];
}
//Build the choices array from query result
$choices = array();
foreach ($questionsArray as $row) {
$choices[$row['questionid']] = array($row['choice1'], $row['choice2'], $row['choice3'], $row['answer']);
}