-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresults.php
More file actions
168 lines (143 loc) · 4.67 KB
/
Copy pathresults.php
File metadata and controls
168 lines (143 loc) · 4.67 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<!DOCTYPE html>
<?php
include 'db_connect.php';
$conn = OpenCon();
$sql = "SELECT how_many FROM results WHERE res = '<50%'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$a = strval($row["how_many"]);
}
}
$sql = "SELECT how_many FROM results WHERE res = '50%-80%'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$b = strval($row["how_many"]);
}
}
$sql = "SELECT how_many FROM results WHERE res = '>80%'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$c = strval($row["how_many"]);
}
}
setcookie("<50%", $a);
setcookie("50%-80%", $b);
setcookie(">80%", $c);
CloseCon($conn);
?>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Result</title>
<link rel="stylesheet" href="styles.css">
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script>
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var a = <?php echo $_COOKIE["<50%"]; ?>;
var b = <?php echo $_COOKIE["50%-80%"]; ?>;
var c = <?php echo $_COOKIE[">80%"]; ?>;
// alert(a);
// alert(b);
// alert(c);
var data = google.visualization.arrayToDataTable([
['Result', 'Percentage'],
['<50%', a],
['50%-80%', b],
['>80%', c],
]);
var options = {'title':'Results among other Friends fans', 'width':550, 'height':400};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}</script>
</head>
<body>
<center><p class="results">
Your result:
<?php
$conn = OpenCon();
$res = 0;
$all = 12;
$A1 = htmlspecialchars($_POST['Question1']);
$A2 = htmlspecialchars($_POST['Question2']);
$A3 = htmlspecialchars($_POST['Question3']);
$A4 = htmlspecialchars($_POST['Question4']);
$A5 = htmlspecialchars($_POST['Question5']);
$A6 = htmlspecialchars($_POST['Question6']);
$A7 = htmlspecialchars($_POST['Question7']);
$A8 = htmlspecialchars($_POST['Question8']);
$A9 = htmlspecialchars($_POST['Question9']);
$A10 = htmlspecialchars($_POST['Question10']);
$A11 = htmlspecialchars($_POST['Question11']);
$A12 = htmlspecialchars($_POST['Question12']);
if($A1 == "Grandmother's"){
$res = $res + 1;
}
if($A2 == "Word Phoebe uses when she can't remember the real thing"){
$res = $res + 1;
}
if($A3 == "2"){
$res = $res + 1;
}
if($A4 == "7"){
$res = $res + 1;
}
if($A5 == "Chandler"){
$res = $res + 1;
}
if($A6 == "Judaism"){
$res = $res + 1;
}
if($A7 == "Rachel"){
$res = $res + 1;
}
if($A8 == "Scotch tape"){
$res = $res + 1;
}
if($A9 == "Ross"){
$res = $res + 1;
}
if($A10 == "All my children"){
$res = $res + 1;
}
if($A11 == "His friend rescued Marcel from some labs"){
$res = $res + 1;
}
if($A12 == "Cheerleaders were practicing the human pyramid and she was on top"){
$res = $res + 1;
}
echo "$res / $all <br>";
if($res/$all > 0.8){
echo "Wow! Congratulations! You know Friends very well <br>";
$sql = "UPDATE results SET how_many=how_many+1 WHERE res='>80%'";
}elseif($res/$all < 0.5){
echo "You definitely need to watch Friends again! <br>";
$sql = "UPDATE results SET how_many=how_many+1 WHERE res='<50%'";
}else{
$sql = "UPDATE results SET how_many=how_many+1 WHERE res='50%-80%'";
}
echo"<br>";
if ($conn->query($sql) === TRUE) {
$sql = "SELECT * FROM results ORDER BY NR";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
// echo "Result: " . $row["res"]. " - " . $row["how_many"]. " <br>";
}
} else {
echo "0 results";
}
} else {
echo "Error updating record: " . $conn->error;
}
CloseCon($conn);
?>
<br>
<div id="piechart"></div>
</p></center>
</body>
</html>