-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhalaman.php
106 lines (75 loc) · 1.91 KB
/
halaman.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
<?php
session_start();
//cek apakah user udah login
if (!isset($_SESSION['username'])) {
header("location:login.php");
}
//cek level admin
if ($_SESSION['level'] != "admin") {
die("ANDA BUKAN USER");
}
?>
<h3>Selamat Datang <?php echo $_SESSION['username']; ?></h3>
<a href="login_m.php?op=out">Logout</a>
<a href="post.php">Post Berita</a>
<hr>
<form action="halaman.php" method="GET">
<input type="text" name="s">
<input type="submit" value="CARI" name="cari">
</form>
<hr>
<?php
error_reporting(E_ALL ^ (E_NOTICE));
$batas = 5;
$halaman = $_GET['halaman'];
if (empty($halaman)) {
$posisi = 0;
$halaman = 1;
}else{
$posisi = ($halaman - 1) * $batas;
}
//koneksi ke database
$konek = mysqli_connect("localhost", "root", "", "berita");
if (isset($_GET['cari'])) {
$q = $_GET['s'];
$tampil = "SELECT * FROM konten WHERE judul LIKE '%$q%' ORDER BY judul LIMIT $posisi, $batas";
}else{
//query menampilkan data
$tampil = "SELECT * FROM konten LIMIT $posisi, $batas";
}
$hasil = mysqli_query($konek,$tampil);
$jmlhasil = mysqli_num_rows($hasil);
?>
<?php
if ($jmlhasil < 1) {
echo "<td colspan='5'>data yang ada cari tidak ada</td>";
}else{
//penomoran
$no = $posisi + 1;
//tampil nama, email dan pesan
while($data=mysqli_fetch_array($hasil)){
echo "judul : $data[judul]<br>";
echo "isi : $data[isi]<br>";
echo "<img src='img/$data[photo]' width='100px'><br>";
echo "<a href='hapus_b.php?id=$data[id]'>hapus</a> |
<a href='edit_b.php?id=$data[id]'>edit</a>|
<a href='berita_a.php?id=$data[id]'>detail</a><hr>";
$no++;
}
}
?>
<?php
//untuk pagging
$tampil2 = "SELECT * FROM konten";
$hasil2 = mysqli_query($konek, $tampil2);
$jmldata = mysqli_num_rows($hasil2);
$jmlhalaman = ceil($jmldata / $batas);
echo " jumlah data : $jmldata <br>";
for ($i=1; $i <= $jmlhalaman; $i++) {
if ($i != $halaman) {
echo "<a href=$_SERVER[PHP_SELF]?halaman=$i> $i </a>";
}else{
echo " <b> $i </b>";
}
}
?>