-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.php
223 lines (192 loc) · 9.61 KB
/
main.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="assets/css/themes.css">
</head>
<body>
<div class="blog-post">
<?php
include "admin/koneksi.php";
$_GET['module']=isset($_GET['module']) ? $_GET['module'] : '';
//tampilkan 5 berita terbaru
if($_GET['module'] ==''){
$terkini = mysqli_query($koneksi,"SELECT * FROM berita ORDER BY id_berita DESC");
while($t=mysqli_fetch_array($terkini)){
$u = mysqli_query($koneksi,"SELECT * FROM user WHERE id='$t[id_user]'");
$nu=mysqli_fetch_array($u);
echo "<a href=?module=detailberita&id=$t[id_berita]><h2 class='blog-post-title'>$t[judul]</h2></a>";
echo "<p class='blog-post-meta'>$t[tgl_posting] | by : $nu[username]</p>";
if($t['gambar']!=''){
echo "<img src='admin/foto_berita/$t[gambar]' width=200 height=100 hspace=10 border=0 align=left>";
}
//tampilkan hanya sebagian berita
$isi_berita = htmlentities(strip_tags($t['isi_berita'])); //membuat paragraf pada isi berita da mengabaikan tag html
$isi = substr($isi_berita, 0,210); //ambil sebanyak 210 karakter
$isi = substr($isi_berita, 0,strrpos($isi," ")); //spasi
echo "<p><br>$isi ... <a class=btn href=?module=detailberita&id=$t[id_berita]>Selengkapnya</a> <br><hr color=white><br><br></p>";
}
}
elseif ($_GET['module']=='detailberita'){
$detail = mysqli_query($koneksi,"SELECT * FROM berita WHERE id_berita = '$_GET[id]'");
$d = mysqli_fetch_array($detail);
$u = mysqli_query($koneksi,"SELECT * FROM user WHERE id = '$d[id_user]'");
$nu = mysqli_fetch_array($u);
if($d['gambar']!=''){
echo "<img src='admin/foto_berita/$d[gambar]' width=800 height=400 hspace=10 border=0 align=left>";
}
echo "<a href=?module=detailberita&id=$d[id_berita]><h2>$d[judul]</h2></a>";
echo "<p class='blog-post-meta'>$d[tgl_posting] | by : $nu[username]</p>";
echo "<p>$d[isi_berita]</p>";
?>
<div class="jumbotron">
<div>
<h2 class="display-4">Komentar</h2>
</div>
<div>
<form role="form" method="POST" action="">
<div class="form-group">
<label>Nama</label>
<input type="text" name="nama" class="form-control" placeholder="Username">
</div>
<div class="form-group">
<label>Email</label>
<input type="text" name="email" class="form-control" placeholder="Username">
</div>
<div class="form-group">
<label>Komentar</label>
<textarea name="komentar" placeholder="komentar anda" class="form-control" rows="5"></textarea>
</div>
<button type="submit" class="btn btn-default" name="btnsubmit"> Submit</button>
</form>
</div>
</div>
<div class="jumbotron">
<?php
$tampil = mysqli_query($koneksi, "SELECT * FROM komentar WHERE id_berita = $_GET[id]");
while($tam = mysqli_fetch_array($tampil)){
echo "<p>$tam[nama] : $tam[isi_komentar]</p>";
}
?>
</div>
<?php
if(isset($_POST['btnsubmit'])){
include "koneksi.php";
$komentar = mysqli_query($koneksi,"INSERT INTO komentar
(id_berita,
nama,
email,
isi_komentar)
VALUES
('$_GET[id]',
'$_POST[nama]',
'$_POST[email]',
'$_POST[komentar]')");
if ($komentar) {
echo "<script> alert('Berhasil menambahkan komentar')</script>";
}
}
echo "<b>[ <a href=javascript:history.go(-1)>Kembali</a> ]</p>";
}
elseif($_GET['module'] =='b_terbaru'){
$sebelum = mysqli_query($koneksi,"SELECT * FROM berita ORDER BY id_berita DESC LIMIT 5");
while($s=mysqli_fetch_array($sebelum)){
echo "<p><a href=?module=detailberita&id=$s[id_berita]>$s[judul]</a></p>";
}
}
elseif($_GET['module'] =='k_terbaru'){
$komentar1 = mysqli_query($koneksi,"SELECT nama,judul,komentar.id_berita FROM komentar join berita where komentar.id_berita = berita.id_berita ORDER BY id_komentar DESC LIMIT 5");
$namaBerita = mysqli_query($koneksi,"SELECT * FROM berita");
while($s=mysqli_fetch_array($komentar1)){
echo "<p><h5>$s[nama] di </h5><a href=?module=detailberita&id=$s[id_berita]>$s[judul]<br></a></p>";
}
}
elseif ($_GET['module']=='teknologi'){
$terkini = mysqli_query($koneksi,"SELECT * FROM berita where id_kategori=1");
while($t=mysqli_fetch_array($terkini)){
$u = mysqli_query($koneksi,"SELECT * FROM user WHERE id='$t[id_user]'");
$nu=mysqli_fetch_array($u);
echo "<a href=?module=detailberita&id=$t[id_berita]><h2 class='blog-post-title'>$t[judul]</h2></a>";
echo "<p class='blog-post-meta'>$t[tgl_posting] | by : $nu[username]</p>";
if($t['gambar']!=''){
echo "<img src='admin/foto_berita/$t[gambar]' width=200 height=100 hspace=10 border=0 align=left>";
}
//tampilkan hanya sebagian berita
$isi_berita = htmlentities(strip_tags($t['isi_berita'])); //membuat paragraf pada isi berita da mengabaikan tag html
$isi = substr($isi_berita, 0,210); //ambil sebanyak 210 karakter
$isi = substr($isi_berita, 0,strrpos($isi," ")); //spasi
echo "<br><p>$isi ... <a class=btn href=?module=detailberita&id=$t[id_berita]>Selengkapnya</a> <br><hr color=white></p><br><br><br>";
}
}
elseif ($_GET['module']=='kesehatan'){
$terkini = mysqli_query($koneksi,"SELECT * FROM berita where id_kategori=2");
while($t=mysqli_fetch_array($terkini)){
$u = mysqli_query($koneksi,"SELECT * FROM user WHERE id='$t[id_user]'");
$nu=mysqli_fetch_array($u);
echo "<a href=?module=detailberita&id=$t[id_berita]><h2 class='blog-post-title'>$t[judul]</h2></a>";
echo "<p class='blog-post-meta'>$t[tgl_posting] | by : $nu[username]</p>";
if($t['gambar']!=''){
echo "<img src='admin/foto_berita/$t[gambar]' width=200 height=100 hspace=10 border=0 align=left>";
}
//tampilkan hanya sebagian berita
$isi_berita = htmlentities(strip_tags($t['isi_berita'])); //membuat paragraf pada isi berita da mengabaikan tag html
$isi = substr($isi_berita, 0,210); //ambil sebanyak 210 karakter
$isi = substr($isi_berita, 0,strrpos($isi," ")); //spasi
echo "<p>$isi ... <a class=btn href=?module=detailberita&id=$t[id_berita]>Selengkapnya</a> <br><hr color=white></p><br><br><br>";
}
}
elseif ($_GET['module']=='sport'){
$terkini = mysqli_query($koneksi,"SELECT * FROM berita where id_kategori=6");
while($t=mysqli_fetch_array($terkini)){
$u = mysqli_query($koneksi,"SELECT * FROM user WHERE id='$t[id_user]'");
$nu=mysqli_fetch_array($u);
echo "<a href=?module=detailberita&id=$t[id_berita]><h2 class='blog-post-title'>$t[judul]</h2></a>";
echo "<p class='blog-post-meta'>$t[tgl_posting] | by : $nu[username]</p>";
if($t['gambar']!=''){
echo "<img src='admin/foto_berita/$t[gambar]' width=200 height=100 hspace=10 border=0 align=left>";
}
//tampilkan hanya sebagian berita
$isi_berita = htmlentities(strip_tags($t['isi_berita'])); //membuat paragraf pada isi berita da mengabaikan tag html
$isi = substr($isi_berita, 0,210); //ambil sebanyak 210 karakter
$isi = substr($isi_berita, 0,strrpos($isi," ")); //spasi
echo "<p>$isi ... <a class=btn href=?module=detailberita&id=$t[id_berita]>Selengkapnya</a> <br><hr color=white></p><br><br><br>";
}
}
elseif ($_GET['module']=='politik'){
$terkini = mysqli_query($koneksi,"SELECT * FROM berita where id_kategori=7");
while($t=mysqli_fetch_array($terkini)){
$u = mysqli_query($koneksi,"SELECT * FROM user WHERE id='$t[id_user]'");
$nu=mysqli_fetch_array($u);
echo "<a href=?module=detailberita&id=$t[id_berita]><h2 class='blog-post-title'>$t[judul]</h2></a>";
echo "<p class='blog-post-meta'>$t[tgl_posting] | by : $nu[username]</p>";
if($t['gambar']!=''){
echo "<img src='admin/foto_berita/$t[gambar]' width=200 height=100 hspace=10 border=0 align=left>";
}
//tampilkan hanya sebagian berita
$isi_berita = htmlentities(strip_tags($t['isi_berita'])); //membuat paragraf pada isi berita da mengabaikan tag html
$isi = substr($isi_berita, 0,210); //ambil sebanyak 210 karakter
$isi = substr($isi_berita, 0,strrpos($isi," ")); //spasi
echo "<p>$isi ... <a class=btn href=?module=detailberita&id=$t[id_berita]>Selengkapnya</a> <br><hr color=white></p><br><br><br>";
}
}
elseif ($_GET['module']=='travel'){
$terkini = mysqli_query($koneksi,"SELECT * FROM berita where id_kategori=8");
while($t=mysqli_fetch_array($terkini)){
$u = mysqli_query($koneksi,"SELECT * FROM user WHERE id='$t[id_user]'");
$nu=mysqli_fetch_array($u);
echo "<a href=?module=detailberita&id=$t[id_berita]><h2 class='blog-post-title'>$t[judul]</h2></a>";
echo "<p class='blog-post-meta'>$t[tgl_posting] | by : $nu[username]</p>";
if($t['gambar']!=''){
echo "<img src='admin/foto_berita/$t[gambar]' width=200 height=100 hspace=10 border=0 align=left>";
}
//tampilkan hanya sebagian berita
$isi_berita = htmlentities(strip_tags($t['isi_berita'])); //membuat paragraf pada isi berita da mengabaikan tag html
$isi = substr($isi_berita, 0,210); //ambil sebanyak 210 karakter
$isi = substr($isi_berita, 0,strrpos($isi," ")); //spasi
echo "<p>$isi ... <a class=btn href=?module=detailberita&id=$t[id_berita]>Selengkapnya</a> <br><hr color=white></p><br><br><br>";
}
}
?>
</div>
</body>
</html>