-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresult.php
249 lines (177 loc) · 6.24 KB
/
result.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<?php
// 項目数
$num_sei = "45906";
$num_mei_man = "54137";
$num_mei_woman = "35765";
if (isset($_POST['type'])) {
// SQL設定読み込み (接続)
require_once('config.php');
// SQLエラーチェック
if( mysqli_connect_errno($connect) ) {
echo mysqli_connect_errno($connect) . ' : ' . mysqli_connect_error($connect);
}
// SQL文字コード設定
mysqli_set_charset( $connect, 'utf8mb4');
// POSTの中身を格納
$select = $_POST['type'];
// 10回ループ
for ($i = 0 ; $i < 10; $i++) {
// POSTの振り分け
switch ($select) {
case "man":
// Ramdom
mt_srand(random_int(-2**31, 2**31-1));
$rand_sei = mt_rand(1, $num_sei);
mt_srand(random_int(-2**31, 2**31-1));
$rand_mei_man = mt_rand(1, $num_mei_man);
// SELECT文を変数に格納
$sql_sei = "select * from sei where id=" . $rand_sei;
$sql_mei = "select * from mei_man where id=" . $rand_mei_man;
// SQLを実行
$query_sei = mysqli_query( $connect, $sql_sei);
$query_mei = mysqli_query( $connect, $sql_mei);
// 判定用
$case_num = "0";
break;
case "woman":
// Ramdom
mt_srand(random_int(-2**31, 2**31-1));
$rand_sei = mt_rand(1, $num_sei);
mt_srand(random_int(-2**31, 2**31-1));
$rand_mei_woman = mt_rand(1, $num_mei_woman);
// SELECT文を変数に格納
$sql_sei = "select * from sei where id=" . $rand_sei;
$sql_mei = "select * from mei_woman where id=" . $rand_mei_woman;
// SQLを実行
$query_sei = mysqli_query( $connect, $sql_sei);
$query_mei = mysqli_query( $connect, $sql_mei);
// 判定用
$case_num = "0";
break;
case "surname":
// Ramdom
mt_srand(random_int(-2**31, 2**31-1));
$rand_sei = mt_rand(1, $num_sei);
// SELECT文を変数に格納
$sql_sei = "select * from sei where id=" . $rand_sei;
// SQLを実行
$query_sei = mysqli_query( $connect, $sql_sei);
// 判定用
$case_num = "1";
break;
case "name-m":
// Ramdom
mt_srand(random_int(-2**31, 2**31-1));
$rand_mei_man = mt_rand(1, $num_mei_man);
// SELECT文を変数に格納
$sql_mei = "select * from mei_man where id=" . $rand_mei_man;
// SQLを実行
$query_mei = mysqli_query( $connect, $sql_mei);
// 判定用
$case_num = "2";
break;
case "name-w":
// Ramdom
mt_srand(random_int(-2**31, 2**31-1));
$rand_mei_woman = mt_rand(1, $num_mei_woman);
// SELECT文を変数に格納
$sql_mei = "select * from mei_woman where id=" . $rand_mei_woman;
// SQLを実行
$query_mei = mysqli_query( $connect, $sql_mei);
// 判定用
$case_num = "2";
break;
}
// 判別
switch ($case_num) {
case "0":
// 結果を変数に格納
while( $result_sei = $query_sei->fetch_array() ) {
while( $result_mei = $query_mei->fetch_array() ) {
$data_sei[$i][0] = $result_sei["name"];
$data_sei[$i][1] = $result_sei["yomi"];
$data_mei[$i][0] = $result_mei["name"];
$data_mei[$i][1] = $result_mei["yomi"];
}}
break;
case "1":
// 結果を変数に格納
while( $result_sei = $query_sei->fetch_array() ) {
$data_sei[$i][0] = $result_sei["name"];
$data_sei[$i][1] = $result_sei["yomi"];
}
break;
case "2":
// 結果を変数に格納
while( $result_mei = $query_mei->fetch_array() ) {
$data_mei[$i][0] = $result_mei["name"];
$data_mei[$i][1] = $result_mei["yomi"];
}
break;
}
}
// SQL接続を閉じる
mysqli_close($connect);
}
?>
<!DOCTYPE html>
<html dir="ltr" lang="ja">
<head>
<meta charset="UTF-8" />
<title>Name Generator</title>
<!-- HTML (Template) Last modified: 2020-07-04 JST Ver. 2.0.0 -->
<meta name="robots" content="none" />
<style>
@font-face {
font-family: Koruri-Regular;
src: local('Koruri-Regular'),
url('https://media.h3z.jp/fonts/Koruri-Regular.woff2') format('woff2'),
url('https://media.h3z.jp/fonts/Koruri-Regular.woff') format('woff'),
url('https://media.h3z.jp/fonts/Koruri-Regular.ttf') format('truetype');
font-weight: 400;
font-style: normal;
font-display: swap;
}
body {
font-family: Koruri-Regular, sans-serif;
text-align: center;
}
div.result {
font-family: Koruri-Regular, sans-serif;
font-size: 2.4em;
}
ul {
list-style-type: none;
}
li {
display: inline;
}
</style>
</head>
<body>
<form action="" method="post">
<label><input type="radio" name="type" value="man"<?php if (isset($select)) { if ($select == "man") { echo " checked"; } } ?> /><span>男性</span></label>
<label><input type="radio" name="type" value="woman"<?php if (isset($select)) { if ($select == "woman") { echo " checked"; } } ?> /><span>女性</span></label>
<label><input type="radio" name="type" value="surname"<?php if (isset($select)) { if ($select == "surname") { echo " checked"; } } ?> /><span>苗字のみ</span></label>
<label><input type="radio" name="type" value="name-m"<?php if (isset($select)) { if ($select == "name-m") { echo " checked"; } } ?> /><span>名前のみ (男性)</span></label>
<label><input type="radio" name="type" value="name-w"<?php if (isset($select)) { if ($select == "name-w") { echo " checked"; } } ?> /><span>名前のみ (女性)</span></label>
<input type="submit" name="submit" value="生成!" />
</form>
<?php if (isset($_POST['type'])) {
echo'<div class="result">' . "\n";
echo" <ul>\n";
for ($i = 0 ; $i < 10; $i++) {
if ($i == 4) {
echo' <li><ruby>' . $data_sei[$i][0] . '<rt>' . $data_sei[$i][1] . '</rt></ruby> <ruby>' . $data_mei[$i][0] . '<rt>' . $data_mei[$i][1] . "</rt></ruby></li>\n";
echo" </ul>\n";
} else if ($i == 5) {
echo" <ul>\n";
echo' <li><ruby>' . $data_sei[$i][0] . '<rt>' . $data_sei[$i][1] . '</rt></ruby> <ruby>' . $data_mei[$i][0] . '<rt>' . $data_mei[$i][1] . "</rt></ruby></li>\n";
} else {
echo' <li><ruby>' . $data_sei[$i][0] . '<rt>' . $data_sei[$i][1] . '</rt></ruby> <ruby>' . $data_mei[$i][0] . '<rt>' . $data_mei[$i][1] . "</rt></ruby></li>\n";
}}
echo" </ul>\n";
echo"</div>\n";
} ?>
</body>
</html>