forked from cse442-at-ub/s24semesterproject-interns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquestion2.php
145 lines (141 loc) · 5.13 KB
/
question2.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Q2</title>
<link rel="stylesheet" href="css/style.css" type="text/css" />
</head>
<body>
<header>
<div class="container">
<h1>Question 2</h1>
</div>
</header>
<style>
body {
font-family: 'Times New Roman', Times, serif, sans-serif;
margin: 0;
padding: 0;
font-size: 20px;
background-color: #C3B1E1;
}
.container {
max-width: 600px;
margin: 50px auto;
padding: 20px;
background-color: #CCCCFF;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1, h2 {
text-align: center;
}
.question {
margin-bottom: 20px;
}
.answer-box {
width: 100%;
padding: 10px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 5px;
box-sizing: border-box;
}
.button-group {
text-align: center;
}
.button-group button {
padding: 10px 20px;
margin: 0 10px;
font-size: 16px;
border: none;
border-radius: 5px;
cursor: pointer;
}
.button-group button.active {
background-color: #4CAF50;
color: white;
}
.next-button {
margin-top: 20px;
background-color: #C3B1E1;
color: white;
}
</style>
<?php
//$dbname = "cse442_2024_spring_team_f_db";
//$dbname = "interns_cse442";
$dbname = "my442db";
$conn = new mysqli("", "root", "", $dbname);
$current = "SELECT data_percent FROM mydb";
$value = $conn->query($current);
$food = 0;
$experience = 0;
$shopping = 0;
$study = 0;
if ($value->num_rows > 0){
while($row = $value->fetch_assoc()){
$dict = json_decode($row["data_percent"],true);
$food = $dict["food"];
$experience = $dict["experience"];
$shopping = $dict["shopping"];
$study = $dict["study"];
}
}
$sum = $food + $experience + $shopping + $study;
if ($sum == 0){
$html_food = "0%";
$html_ex = "0%";
$html_shop = "0%";
$html_study = "0%";
}else{
$html_food = strval(round(($food/$sum)*100,2) . '%');
$html_ex = strval(round(($experience/$sum)*100,2) . '%');
$html_shop = strval(round(($shopping/$sum)*100,2) . '%');
$html_study = strval(round(($study/$sum)*100 ,2). '%');
}
?>
<main>
<div class="container">
<form method="post" action="back.php">
<input class="next-button" type="submit" name="back2" value="BACK">
</form>
<form method="post" action="quizpage.php">
<p class="question">
<label>What is the purpose of your travel?</label>
</p>
<ul class="choices">
<li><input name="purpose_choice" type="radio" onclick="recordClick('option1')" value="For Food" />For Food</li>
<?php echo "Selected percentage: $html_food<br>";?>
<li><input name="purpose_choice" type="radio" onclick="recordClick('option2')" value="For the experience" />For the experience</li>
<?php echo "Selected percentage: $html_ex<br>";?>
<li><input name="purpose_choice" type="radio" onclick="recordClick('option3')" value="For Shopping" />For Shopping</li>
<?php echo "Selected percentage: $html_shop<br>";?>
<li><input name="purpose_choice" type="radio" onclick="recordClick('option4')" value="For Academic Purpose" />For Academic Purpose</li>
<?php echo "Selected percentage: $html_study<br>";?>
</ul>
<button class="next-button" id="next">NEXT</button>
<script>
// Get the button element
var button = document.getElementById("next");
// Add a click event listener to the button
button.addEventListener("click", function() {
var purpose_choice = document.querySelector('input[name="purpose_choice"]:checked');
if (!purpose_choice) {
//window.location.replace("question1.php");
alert("You have not selected any options yet!");
<?php session_start();$_SESSION['question2'] = False;?>
}
});
</script>
</form>
</div>
</main>
<footer>
<div class="container">
Interns ©2024, Quiz
</div>
</footer>
</body>
</html>