-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
79 lines (66 loc) · 2.08 KB
/
Copy pathindex.php
File metadata and controls
79 lines (66 loc) · 2.08 KB
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
<?php
session_start();
include 'includes/db.php';
// ログインしていない場合はウェルカムページにリダイレクト
if (!isset($_SESSION['user_id'])) {
header("Location: welcome.php");
exit();
}
// 検索フォームで送信された値を受け取ります
$searchTags = isset($_POST['search_tags']) ? $_POST['search_tags'] : '';
?>
<!DOCTYPE html>
<html>
<head>
<title>Pet Photo App</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<header>
<div class="header-title">
<h1>Pet Photo App</h1>
</div>
<div class="upload-form-button">
<a href="upload_form.php">投稿</a>
</div>
</header>
<!-- 検索フォーム -->
<div class="search-bar">
<form action="index.php" method="POST">
<input type="text" id="search_tags" name="search_tags" value="<?php echo $searchTags; ?>">
<button type="submit">検索</button>
</form>
</div>
<main>
<div class="photos">
<?php
// 検索フォームで送信された値を使用して、写真を絞り込むクエリを作成します
$sql = "SELECT * FROM photos";
if (!empty($searchTags)) {
$sql .= " WHERE tags LIKE :searchTags";
}
$stmt = $conn->prepare($sql);
if (!empty($searchTags)) {
$searchParam = '%' . $searchTags . '%';
$stmt->bindParam(':searchTags', $searchParam);
}
$stmt->execute();
$rowCount = $stmt->rowCount();
if ($rowCount > 0) {
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo "<div class='photo'>";
echo "<img src='" . $row["filename"] . "' alt='Pet Photo'>";
echo "<p>ジャンル: " . $row["tags"] . "</p>";
echo "</div>";
}
} else {
echo "写真がありません。";
}
?>
</div>
</main>
<footer>
<p>© <?php echo date("Y"); ?> Pet Photo App</p>
</footer>
</body>
</html>