-
Notifications
You must be signed in to change notification settings - Fork 0
/
setting.php
99 lines (98 loc) · 3.25 KB
/
setting.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
<?php
require_once 'conf.php'; // confファイル読み込み
// confファイルからデータ取り出す
$dbname = conf("dbname");
$dbhost = conf("dbhost");
$dbusername = conf("dbusername");
$dbpassword = conf("dbpassword");
$dbtable = conf("dbtable");
echo <<<date
<h2>記録されたデータ</h2>
<p>今日入った人</p>
date;
try{
// (1)接続
$db = new PDO("mysql:host=$dbhost;dbname=$dbname", "$dbusername", "$dbpassword");
// (2) SQLクエリ作成
$time = date('Y-m-d');
$stmt = $db->prepare("SELECT * FROM $dbtable WHERE time LIKE '$time %';");
// (3) SQLクエリ実行
$res = $stmt->execute();
if($res) {
// (4) 該当するデータを取得
$all = $stmt->fetchAll();
echo "<table>";
echo <<< date
<tr>
<th>id</th>
<th>name</th>
<th>time</th>
</tr>
date;
foreach($all as $loop){
// (5) 結果を表示
echo "<tr>";
echo "<td>" . $loop["id"] . " " . "</td>";
echo "<td>" .$loop["name"] . " " . "</td>";
echo "<td>" .$loop["time"] . " " . "</td>";
echo "</tr>";
}
echo "</table>";
}
// 切断
$db = null;
} catch(PDOException $e){
echo "データベース接続失敗<br>";
echo $e->getMessage();
}
// 一覧表示
echo <<<date
<p>入った人履歴</p>
date;
try{
// (1)接続
$db = new PDO("mysql:host=$dbhost;dbname=$dbname", "$dbusername", "$dbpassword");
// (2) SQLクエリ作成
$stmt = $db->prepare("SELECT * FROM $dbtable;");
// (3) SQLクエリ実行
$res = $stmt->execute();
if($res) {
// (4) 該当するデータを取得
$all = $stmt->fetchAll();
echo "<table>";
echo <<< date
<tr>
<th>id</th>
<th>name</th>
<th>time</th>
</tr>
date;
foreach($all as $loop){
// (5) 結果を表示
echo "<tr>";
echo "<td>" . $loop["id"] . " " . "</td>";
echo "<td>" .$loop["name"] . " " . "</td>";
echo "<td>" .$loop["time"] . " " . "</td>";
echo <<<DATA
<td>
<form action="./delete.php" method="GET">
<div>
DATA;
echo '<input type="hidden" name="id" value="' . $loop["id"] . '">';
echo <<<DATA
<button type="submit">del</button>
</div>
</form>
</td>
DATA;
echo "</tr>";
}
echo "</table>";
}
// 切断
$db = null;
} catch(PDOException $e){
echo "データベース接続失敗<br>";
echo $e->getMessage();
}
?>