-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
124 lines (108 loc) · 4.3 KB
/
index.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="bootstrap-5.3.2-dist/css/bootstrap.min.css">
<script src="bootstrap-5.3.2-dist/js/bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.min.css">
<title>Webboard nine</title>
<script>
function myFunction() {
let r = confirm("ต้องการจะลบจริงหรือไม่?")
return r;
}
</script>
</head>
<body>
<div class="container-lg">
<h1 style="text-align: center;" class="mt-3">Webboard KakKak</h1>
<?php include "nav.php" ?>
<div class="mt-3 d-flex justify-content-between">
<div>
<label>หมวดหมู่</label>
<span class="dropdown">
<?php
$conn = new PDO("mysql:host=localhost;dbname=webboard;charset=utf8", "root", "");
?>
<button class="btn btn-white-50 btn-sm dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
<?php
if (isset($_GET['id'])) {
$sql = "SELECT name FROM category WHERE id=$_GET[id]";
foreach ($conn->query($sql) as $row)
echo "$row[name]";
} else {
echo "--ทั้งหมด--";
}
?>
</button>
<ul class="dropdown-menu" aria-labelledby="Button2" >
<?php
$conn = new PDO("mysql:host=localhost;dbname=webboard;charset=utf8", "root", "");
$sql = "SELECT * FROM category";
foreach ($conn->query($sql) as $row) {
echo "<li><a class=dropdown-item href='index.php?id=$row[id]' >$row[1]</a></li>";
}
$conn = null;
?>
</ul>
</span>
</div>
<?php if (isset($_SESSION['id'])) { ?>
<div>
<a href="newpost.php" class="btn btn-success btn-sm"><i class="bi bi-plus"></i> สร้างกระทู้ใหม่</a>
</div>
<?php } ?>
</div>
<table class="table table-striped mt-4 ">
<?php
$conn = new PDO("mysql:host=localhost;dbname=webboard;charset=utf8", "root", "");
if (isset($_GET['id'])) {
$sql = "SELECT t3.name,t1.title,t1.id,t2.login,t1.post_date,t2.id as 'user_id' FROM post as t1
INNER JOIN user as t2 ON (t1.user_id=t2.id)
INNER JOIN category as t3 ON (t1.cat_id=t3.id)
WHERE t1.cat_id=$_GET[id]
ORDER BY t1.post_date DESC";
} else {
$sql = "SELECT t3.name,t1.title,t1.id,t2.login,t1.post_date,t2.id as 'user_id' FROM post as t1
INNER JOIN user as t2 ON (t1.user_id=t2.id)
INNER JOIN category as t3 ON (t1.cat_id=t3.id)
ORDER BY t1.post_date DESC";
}
$result = $conn->query($sql);
while ($row = $result->fetch()) {
echo "<tr><td class='d-flex justify-content-between'>
<div>[ $row[0] ] <a href=post.php?id=$row[2]
style=text-decoration:none>$row[1]</a><br>$row[3] - $row[4]</div>";
if (isset($_SESSION['id']) && $_SESSION['role'] == 'a') {
if ($_SESSION['username'] == $row[3]) {
echo "<div class='me-2 align-self-center'>
<a href=editpost.php?id=$row[2]
class='btn btn-warning btn-sm'><i class='bi bi-pencil-fill'></i></a>
<a href=delete.php?id=$row[2]
class='btn btn-danger btn-sm' onclick='return myFunction()'><i class='bi bi-trash'></i></a>
</div>";
} else {
echo "<div class='me-2 align-self-center'>
<a href=delete.php?id=$row[2]
class='btn btn-danger btn-sm' onclick='return myFunction()'><i class='bi bi-trash'></i></a>
</div>";
}
} else if (isset($_SESSION['id']) && $_SESSION['username'] == $row[3]) {
echo "<div class='me-2 align-self-center'>
<a href=editpost.php?id=$row[2]
class='btn btn-warning btn-sm'><i class='bi bi-pencil-fill'></i></a>
<a href=delete.php?id=$row[2]
class='btn btn-danger btn-sm' onclick='return myFunction()'><i class='bi bi-trash'></i></a>
</div>";
}
}
$conn = null;
?>
</table>
</div>
</body>
</html>