forked from prakharsingh1312/cusiege
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre.php
More file actions
82 lines (46 loc) · 1.4 KB
/
Copy pathpre.php
File metadata and controls
82 lines (46 loc) · 1.4 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
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
<?php
session_start();
require_once('Assets/php/dbconfig.php');
//Choose Table accordingly
$table=$_SESSION['table'];
//Create a query to fetch all the questions
$query = "select * from pre_$table";
//Run the query
$query_result = $dbconfig->query($query);
//Count the number of returned items from the database
$num_questions_returned = $query_result->num_rows;
if ($num_questions_returned < 1){
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();
$questions = array();
$text = array();
$choices = array();
$tie = array();
shuffle($questionsArray);
$i=1;
foreach($questionsArray as $question){
$correctAnswerArray[$i] = $question['answer'];
$questions[$i] = $question['question'];
$text[$i]=$question['text'];
$tie[$i]=$question['tie'];
if($question['text']==0)
{$choices[$i] = array($question['choice1'], $question['choice2'], $question['choice3'], $question['answer']);
shuffle($choices[$i]);
}
$i++;
}
$_SESSION['cans']=$correctAnswerArray;
$_SESSION['q']=$questions;
$_SESSION['text']=$text;
$_SESSION['tie']=$tie;
$_SESSION['choices']=$choices;
$_SESSION['numq']=$num_questions_returned;
header('location:play');
?>