forked from prakharsingh1312/Helloworld
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre.php
More file actions
90 lines (55 loc) · 1.74 KB
/
pre.php
File metadata and controls
90 lines (55 loc) · 1.74 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
82
83
84
85
86
87
88
89
<?php
session_start;
require_once('Assets/php/dbconfig.php');
//Choose Table accordingly
$table='admin_'.$_SESSION['id'].'_'.$_SESSION['cid'].'_pre';
//Create a query to fetch all the questions
$query = "select * from $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();
$qid= array();
$points=array();
shuffle($questionsArray);
$i=1;
foreach($questionsArray as $question){
$qid[$i]=$question['qid'];
$points[$i]=$question['points'];
$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;
$_SESSION['qid']=$qid;
$_SESSION['points']=$points;
$query=$dbconfig->prepare("INSERT INTO admin_{$_SESSION['id']}_{$_SESSION['cid']}_res (userid) values (?)");
$query->bind_param("i",$_SESSION['uid']);
$query->execute();
header('location:play.php');
?>