-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboard_template.php
80 lines (76 loc) · 2.75 KB
/
board_template.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
<?php
require_once('config.php');
?>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>掲示板</title>
</head>
<body>
<div class="infoMessage"><?= $info ?></div>
<form action="post.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="id" value="">
<input type="hidden" name="parentId" value="0">
<button type="submit" name="post">新規投稿</button>
</form>
<form action="logout.php" method="post">
<button type="submit" name="logout">ログアウト</button>
</form>
<h1>最新の投稿10件とコメント最大10件を表示します。</h1>
<?php
try {
$pdo = new PDO(DSN, DB_USER, DB_PASS);
$stmt = $pdo->prepare('select * from posts where parentId = 0 order by id DESC Limit 10');
$stmt->execute();
} catch (\Exception $e) {
$info = '投稿がよみこめませんでした。';
}
foreach ($stmt as $row) {
?>
<div class="post">
<form action="post.php" method="post">
<input type="hidden" name="parentId" value="<?= $row['id'] ?>">
<h2>投稿:<?= $row['email'] ?></h2>
<p>message:<?= $row['message'] ?></p>
<p><img src="<?= $row['imagePath'] ?>"></p>
<button type="submit" name="commentPost">コメントする</button>
</form>
<?php if ($_SESSION['email'] == $row['email']) : ?>
<form action="delete.php" method="post">
<input type='hidden' name="id" value="<?= $row['id'] ?>">
<button type="submit" name="deletePost">削除</button>
</form>
<?php endif; ?>
<?php
try {
$stmt2 = $pdo->prepare('select * from posts where parentId = ? order by id DESC');
$stmt2->execute([ $row['id'] ]);
} catch (\Exception $e) {
$info = '投稿がよみこめませんでした。';
}
foreach ($stmt2 as $row2) {
?>
<form action="post.php" method="post">
<input type="hidden" name="parentId" value="<?= $row['id'] ?>">
<h4>コメント:<?= $row2['email'] ?></h4>
<p>message:<?= $row2['message'] ?></p>
<p><img src="<?= $row2['imagePath'] ?>"></p>
<button type="submit" name="commentPost">コメントする</button>
</form>
<?php if ($_SESSION['email'] == $row2['email']) : ?>
<form action="delete.php" method="post">
<input type='hidden' name="id" value="<?= $row2['id'] ?>">
<button type="submit" name="deletePost">削除</button>
</form>
<?php endif; ?>
<?php
}
?>
<hr>
</div>
<?php
}
?>
</body>
</html>