forked from seungeunn/webgrus_team7
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnect.php
121 lines (97 loc) · 2.94 KB
/
connect.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
<?php
$conn= mysqli_connect('localhost', 'mbti', '9786', 'WEB' );
$result_mbti = ($_GET['hiddenMbti']);
$selected_job = ($_GET['hiddenJob']);
/*
echo $result_mbti;
echo $selected_job;
*/
mysqli_query($conn, "set session character_set_connection=utf8;");
mysqli_query($conn, "set session character_set_results=utf8;");
mysqli_query($conn, "set session character_set_client=utf8;");
$sql = "
INSERT INTO MBTI
(result_mbti, selected_job, datetime)
VALUES(
'{$result_mbti}',
'{$selected_job}',
NOW()
)
";
$result = mysqli_query($conn, $sql);
if($result === false){
echo '저장하는 과정에서 문제가 생겼습니다. 관리자에게 문의해주세요 ';
error_log(mysqli_error($conn));
}
$sql_total_people = "SELECT COUNT(*) FROM MBTI WHERE result_mbti = '".$result_mbti."';";
$result = mysqli_query($conn, $sql_total_people);
$result = mysqli_fetch_array($result);
$total = $result['COUNT(*)'];
$sql = "SELECT selected_job, count(*) FROM MBTI WHERE result_mbti='".$result_mbti."' GROUP BY selected_job;";
$result= mysqli_query($conn, $sql);
$sql_total_mbti = "SELECT COUNT(*) FROM MBTI";
$resultt = mysqli_query($conn, $sql_total_mbti);
$resultt = mysqli_fetch_array($resultt);
$total_mbti = $resultt['COUNT(*)'];
/*$result_set = mysqli_fetch_array($result);*/
/*while($row = mysqli_fetch_array($result)){
echo $row['selected_job']." ".$row['count(*)'];
echo '<br>';
}*/
?>
<!doctype html>
<html>
<head>
<title>STATISTICS</title>
<link
href="https://fonts.googleapis.com/css2?family=Jua&display=swap"
rel="stylesheet"
/>
<meta charset="utf-8">
<link rel="stylesheet" href="statistics_style.css">
</head>
<body>
<div>
<?php
$percent = round($total / $total_mbti * 100);
echo" <p>{$percent}%의 <span>{$result_mbti}</span>
가 <br>선호하는 직업의 순위는 <br>아래와 같습니다. </p>"
?>
</div>
<br><br>
<table>
<th>NO.</th>
<th>Name</th>
<th>Value</th>
<?php
$i = 1;
while($row = mysqli_fetch_array($result)){
$percentage = round($row['count(*)'] / $total * 100, 2);
echo "<tr>
<td>{$i}</td>
<td>{$row['selected_job']}</td>
<td>{$percentage}%</td>
</tr>";
echo '<br>';
$i++;
}
?>
</table>
<br><br><br><br><br><br>
<div id="button">
<a href="#" class="button" onclick="copy()">링크 공유하기</a>
</div>
<script>
function copy() {
var url = "http://118.67.133.92/start/start.html";
var textarea = document.createElement("textarea");
document.body.appendChild(textarea);
textarea.value = url;
textarea.select();
document.execCommand("copy");
document.body.removeChild(textarea);
alert("URL이 복사되었습니다.");
}
</script>
</body>
</html>