-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_base.php
101 lines (83 loc) · 4.47 KB
/
data_base.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
<?php
require_once "./dbc.php";
$dbo = connectDB();
//SQL作成
$sql = "SELECT * FROM fishing_db";
$stmt = $dbo->prepare($sql);
$status = $stmt->execute();
if($status = false){
$error = $stmt->errorInfo();
exit('sqlError'.$erroe[2]);
}else{
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
//アコーディオン生成
$output ="";
foreach($result as $record){
// $i = 0;
$output .= "<div class='card-header' id='heading{$record['id']}'>
<h2 class='mb-0'>
<button class='btn btn-link' type='button' data-toggle='collapse'
data-target='#collapse{$record['id']}' aria-expanded='true'
aria-controls='collapseOne'>{$record['fish_name']}:{$record['fish_size']}cm {$record['insert_time']}</button><a href='delete.php?id={$record['id']}&訂正'>
<button class=\"clear-btn\" id=\"clear-btn{$record['id']}\" name=\"{$record['id']}\">訂正</button></a>
<a href='delete.php?id={$record['id']}&削除'>
<button class=\"clear-btn\" id=\"clear-btn{$record['id']}\" name=\"{$record['id']}\">削除</button></a></h2></div>
<div class=\"collapse\" id=\"collapse{$record['id']}\" ariaLabelledby=\"heading{$record['id']}\" dataParent=\"#accordionExample\">
<div class=\"card-wrapper card-wrapper{$record['id']}\" style=\"display:flex\">
<div class=\"card-body\">{$record['setsumei']}<br><span class=\"env\">気温:{$record['temp']}℃/ 水温:{$record['water_temp']}℃/風速(風向):{$record['win']}km/h/({$record['win_dir']})</span>
</div>
<!-- img file from DB -->
<div class=\"img-box\"><img id=\"img{$record['id']}\" src=\"./{$record['file_path']}\" alt=\"\" width=\"100%\" height=\"150px\"></div></div></div>";
}
}
?>
<!-- 以下HTML -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Data base</title>
<meta name="descliption" content="a tool for fishing data">
<meta name="format-detection" contetn="telephone-no">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
<link rel="stylesheet" href="css_memo.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/locale/ja.js"></script>
</head>
<body>
<!-- ここから、データベース反映 -->
<h1 style="text-align: left;">Data Base</h1>
<h3><a href="./index.html">fishig_data</a></h3>
<div id="data-wrapper" class="database-wrapper" style="background-color:cadetblue">
<!-- Div -->
<div class="memo-wrapper" id="memo-wrapper">
<div class="accordion" id="accordionExample">
<div class="card" >
<!-- データ数に応じてアコーディオン挿入 -->
<?=$output?>
</div>
</div>
</div>
</div>
<script>
document.addEventListener("click",function(e){
if(e.target.innerHTML==='削除'){
console.log(e.target.innerHTML);
console.log(e.target.name)
let xhr = new XMLHttpRequest();
xhr.open('POST','delete.php',true);
// request.responseType ='html';
// request.addEventListener('load',function(response){
// console.log(response);
// });
request.send();
};
})
</script>
</body>
</html>