-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
118 lines (103 loc) · 4.83 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
<!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="home.css">
<title>Document</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.min.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL"
crossorigin="anonymous"></script>
</head>
<header>
<h1 style="color: pink;">Wasin Budprom</h1>
</header>
<body class="container">
<?php @include('nav.php')?>
<div class="my-2 d-flex justify-content-between">
<div>
<lable>หมวดหมู่</lable>
<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
$sql="SELECT * FROM category";
echo "<li><a class='dropdown-item' href='index.php'> --ทั้งหมด-- </a></li>";
foreach($conn->query($sql)as $row){
echo "<li><a class='dropdown-item' href='index.php?id=$row[id]' onclick='ses()'>$row[name]</a></li>";
}
$conn=null;
?>
</ul>
</span>
</div>
<div>
<?php if (isset($_SESSION['id'])) { ?>
<a href="newpost.php" class="btn btn-success btn-sm"><i class="bi bi-plus-lg"></i> สร้างกระทู้ใหม่</a>
<?php } ?>
</div>
</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'>
<div class='flex-grow-1'>[ $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'])){
if($_SESSION['user_id']==$row['user_id']){
echo "<div class='me-2 align-self-center'><a href='editpost.php?id=$row[2]'
class='btn btn-warning btn-sm' onclick=''><i class='bi bi-pencil-fill'></i></a></div>";
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($_SESSION['role']=='a'){
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>";
}
}
}
$conn=null;
?>
</table>
<script>
function myFunction(){
let r=confirm("แน่น๊ะ?");
return r;
}
function ses(){
return $_SESSION['cat_id']="success";
}
</script>
</body>
</html>