質問編集履歴
4
追記修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -280,7 +280,25 @@
|
|
280
280
|
|
281
281
|
+----+-----------+--------------------+----------+------+-----------+---------+--------+
|
282
282
|
|
283
|
-
|
283
|
+
テーブル名:users
|
284
|
+
|
285
|
+
+----+-----------+--------------------+
|
286
|
+
|
287
|
+
| id | name | email |
|
288
|
+
|
289
|
+
+----+-----------+--------------------+
|
290
|
+
|
291
|
+
| 1 | user1 | user1@test.com |
|
292
|
+
|
293
|
+
+----+-----------+--------------------+
|
294
|
+
|
295
|
+
| 2 | user2 | user2@test.com |
|
296
|
+
|
297
|
+
+----+-----------+--------------------+
|
298
|
+
|
299
|
+
| 3 | user3 | user3@test.com |
|
300
|
+
|
301
|
+
+----+-----------+--------------------+
|
284
302
|
|
285
303
|
```
|
286
304
|
|
3
追記修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -142,6 +142,48 @@
|
|
142
142
|
|
143
143
|
|
144
144
|
|
145
|
+
app.get("/", async (req, res) => {
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
const usr_sql = "select * from users";
|
150
|
+
|
151
|
+
const sql = "select * from users_result";
|
152
|
+
|
153
|
+
let results = await queryAsync(sql);
|
154
|
+
|
155
|
+
let userdata = await queryAsync(usr_sql);
|
156
|
+
|
157
|
+
console.log(userdata);
|
158
|
+
|
159
|
+
console.log(results);
|
160
|
+
|
161
|
+
res.render("index.ejs",{ content: results,userdata: userdata });
|
162
|
+
|
163
|
+
});
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
app.post("/", async (req, res) => {
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
var dt = new Date;
|
172
|
+
|
173
|
+
var now = dt.toFormat("HH24:MI:SS");
|
174
|
+
|
175
|
+
console.log("request", req.body.name);
|
176
|
+
|
177
|
+
const sql = "INSERT INTO users_result SET ?";
|
178
|
+
|
179
|
+
const resid = await queryAsync("select max(id) from users_result");
|
180
|
+
|
181
|
+
const preid = resid[0]["max(id)"];
|
182
|
+
|
183
|
+
const id = preid + 1;
|
184
|
+
|
185
|
+
|
186
|
+
|
145
187
|
const checkname = "SELECT status FROM users_result WHERE name = ?";
|
146
188
|
|
147
189
|
var status_checked = await queryAsync(checkname, req.body.name);
|
@@ -244,6 +286,178 @@
|
|
244
286
|
|
245
287
|
|
246
288
|
|
289
|
+
###追加
|
290
|
+
|
291
|
+
```HTML
|
292
|
+
|
293
|
+
<body>
|
294
|
+
|
295
|
+
<header>
|
296
|
+
|
297
|
+
<h1>練習</h1>
|
298
|
+
|
299
|
+
</header>
|
300
|
+
|
301
|
+
<form action="/" method="POST">
|
302
|
+
|
303
|
+
<span>名前</span>
|
304
|
+
|
305
|
+
<select id="name" name="name">
|
306
|
+
|
307
|
+
<% for(var j in userdata) {%>
|
308
|
+
|
309
|
+
<% var usr_obj = userdata[j]; %>
|
310
|
+
|
311
|
+
<option value= <%= usr_obj.name %>>
|
312
|
+
|
313
|
+
<%= usr_obj.name %>
|
314
|
+
|
315
|
+
</option>
|
316
|
+
|
317
|
+
<% } %>
|
318
|
+
|
319
|
+
</select>
|
320
|
+
|
321
|
+
<% for(var k in userdata) {%>
|
322
|
+
|
323
|
+
<% var mail_obj = userdata[k]; %>
|
324
|
+
|
325
|
+
<input type="hidden" id=<%= mail_obj.name %> value=<%= mail_obj.mail %>>
|
326
|
+
|
327
|
+
<% } %>
|
328
|
+
|
329
|
+
<label><span>メールアドレス</span><input id="mail" name="mail"></label>
|
330
|
+
|
331
|
+
<div class="container">
|
332
|
+
|
333
|
+
<button class="btn btn-lg btn-primary" id="start" name="start_button" type="submit" value="current_time">開始</button>
|
334
|
+
|
335
|
+
<button class="btn btn-lg btn-danger" id="end" name="end_button" type="submit" value="current_time">終了</button>
|
336
|
+
|
337
|
+
<button class="btn btn-lg btn-success" id="restart" name="restart_button" type="submit" value="current_time">途中計測</button>
|
338
|
+
|
339
|
+
<button class="btn btn-lg btn-warning" id="finish" name="finish_button" type="submit" value="current_time">途中終了</button>
|
340
|
+
|
341
|
+
</div>
|
342
|
+
|
343
|
+
</form>
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
<div class="container-fluid">
|
348
|
+
|
349
|
+
<div class="row">
|
350
|
+
|
351
|
+
<div class="col no-gutters">
|
352
|
+
|
353
|
+
<table class="table table-hover table-sm">
|
354
|
+
|
355
|
+
<thead class="thead-dark">
|
356
|
+
|
357
|
+
<tr>
|
358
|
+
|
359
|
+
<th scope="col">ID</th>
|
360
|
+
|
361
|
+
<th scope="col">名前</th>
|
362
|
+
|
363
|
+
<th scope="col">メールアドレス</th>
|
364
|
+
|
365
|
+
<th scope="col">開始</th>
|
366
|
+
|
367
|
+
<th scope="col">終了</th>
|
368
|
+
|
369
|
+
<th scope="col">途中計測開始</th>
|
370
|
+
|
371
|
+
<th scope="col">途中計測終了</th>
|
372
|
+
|
373
|
+
</tr>
|
374
|
+
|
375
|
+
</thead>
|
376
|
+
|
377
|
+
<tbody>
|
378
|
+
|
379
|
+
<% for(var i in content) { %>
|
380
|
+
|
381
|
+
<tr>
|
382
|
+
|
383
|
+
<% var obj = content[i]; %>
|
384
|
+
|
385
|
+
<th><%= obj.id %></th>
|
386
|
+
|
387
|
+
<th><%= obj.name %></th>
|
388
|
+
|
389
|
+
<th><%= obj.email %></th>
|
390
|
+
|
391
|
+
<th><%= obj.start %></th>
|
392
|
+
|
393
|
+
<th><%= obj.end %></th>
|
394
|
+
|
395
|
+
<th><%= obj.restart %></th>
|
396
|
+
|
397
|
+
<th><%= obj.finish %></th>
|
398
|
+
|
399
|
+
</tr>
|
400
|
+
|
401
|
+
<% } %>
|
402
|
+
|
403
|
+
</tbody>
|
404
|
+
|
405
|
+
</table>
|
406
|
+
|
407
|
+
</div>
|
408
|
+
|
409
|
+
</div>
|
410
|
+
|
411
|
+
</div>
|
412
|
+
|
413
|
+
</body>
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
<script>
|
418
|
+
|
419
|
+
document.getElementById("name").addEventListener('change',changename);
|
420
|
+
|
421
|
+
function changename(){
|
422
|
+
|
423
|
+
let name = document.getElementById("name");
|
424
|
+
|
425
|
+
let mail = document.getElementById("mail");
|
426
|
+
|
427
|
+
let hidden_mail = document.getElementById(name.value);
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
|
432
|
+
|
433
|
+
mail.value = hidden_mail.value;
|
434
|
+
|
435
|
+
}
|
436
|
+
|
437
|
+
</script>
|
438
|
+
|
439
|
+
|
440
|
+
|
441
|
+
```
|
442
|
+
|
443
|
+
```MySQL
|
444
|
+
|
445
|
+
テーブル名:users_result
|
446
|
+
|
447
|
+
+----+-----------+--------------------+----------+------+-----------+---------+--------+
|
448
|
+
|
449
|
+
| id | name | email | start | end | restart | finish | status |
|
450
|
+
|
451
|
+
+----+-----------+--------------------+----------+------+-----------+---------+--------+
|
452
|
+
|
453
|
+
| 1 | user1 | user1@test.com | 12:00:00 | NULL | NULL | NULL | 1 |
|
454
|
+
|
455
|
+
+----+-----------+--------------------+----------+------+-----------+---------+--------+
|
456
|
+
|
457
|
+
```
|
458
|
+
|
459
|
+
|
460
|
+
|
247
461
|
|
248
462
|
|
249
463
|
### 補足情報(FW/ツールのバージョンなど)
|
2
文法の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -62,7 +62,7 @@
|
|
62
62
|
|
63
63
|
if(checked == false){
|
64
64
|
|
65
|
-
let updatesql = "UPDATE users SET end = ?, status = ? WHERE name = ?";
|
65
|
+
let updatesql = "UPDATE users_result SET end = ?, status = ? WHERE name = ?";
|
66
66
|
|
67
67
|
var results = await queryAsync(updatesql, [time, 2, req.body.name]);
|
68
68
|
|
@@ -86,7 +86,7 @@
|
|
86
86
|
|
87
87
|
if(checked == true){
|
88
88
|
|
89
|
-
let updatesql = "UPDATE users SET restart = ?, status = ? WHERE name = ?";
|
89
|
+
let updatesql = "UPDATE users_result SET restart = ?, status = ? WHERE name = ?";
|
90
90
|
|
91
91
|
var results = await queryAsync(updatesql, [time, 3, req.body.name]);
|
92
92
|
|
@@ -106,7 +106,7 @@
|
|
106
106
|
|
107
107
|
if(checked == null){
|
108
108
|
|
109
|
-
let updatesql = "UPDATE users SET finish = ?, status = ? WHERE name = ?";
|
109
|
+
let updatesql = "UPDATE users_result SET finish = ?, status = ? WHERE name = ?";
|
110
110
|
|
111
111
|
var results = await queryAsync(updatesql, [time, 1 , req.body.name]);
|
112
112
|
|
1
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -96,7 +96,7 @@
|
|
96
96
|
|
97
97
|
};
|
98
98
|
|
99
|
-
}else if(req.body.
|
99
|
+
}else if(req.body.finish_button){
|
100
100
|
|
101
101
|
let nullcheck = await queryAsync(checkcolumn, ['finish', req.body.name]);
|
102
102
|
|