SHOW:
|
|
- or go back to the newest paste.
| 1 | <?php | |
| 2 | - | require_once "core/init.php"; |
| 2 | + | //require_once "core/init.php"; |
| 3 | function tampilkan(){
| |
| 4 | ||
| 5 | $query = "SELECT * FROM blog order by waktu DESC"; | |
| 6 | return result($query); | |
| 7 | } | |
| 8 | ||
| 9 | function tampilkan_per_id($id){
| |
| 10 | ||
| 11 | $query = "SELECT * FROM blog WHERE id=$id"; | |
| 12 | return result($query); | |
| 13 | } | |
| 14 | ||
| 15 | function hasil_cari($cari){
| |
| 16 | $query = "SELECT * FROM blog WHERE isi LIKE '%$cari%'"; | |
| 17 | return result($query); | |
| 18 | ||
| 19 | } | |
| 20 | ||
| 21 | function result($query){
| |
| 22 | global $link; | |
| 23 | $result= mysqli_query($link, $query); | |
| 24 | if ($result ){
| |
| 25 | return $result; | |
| 26 | }else{
| |
| 27 | or die ('gagal :'.mysqli_error()."<br/>".$sql);
| |
| 28 | return false; | |
| 29 | } | |
| 30 | ||
| 31 | ||
| 32 | } | |
| 33 | ||
| 34 | function tambah_data($judul, $konten , $tag){
| |
| 35 | $query = "INSERT INTO blog(judul, isi , tag) VALUES ('$judul', '$konten' , '$tag')";
| |
| 36 | return run($query); | |
| 37 | ||
| 38 | } | |
| 39 | ||
| 40 | function edit_data($judul, $konten, $tag, $id){
| |
| 41 | $query = "UPDATE blog SET judul='$judul', isi='$konten', tag='$tag'WHERE id=$id"; | |
| 42 | return run($query); | |
| 43 | ||
| 44 | } | |
| 45 | ||
| 46 | function hapus_data($id){
| |
| 47 | $query = "DELETE FROM blog WHERE id=$id"; | |
| 48 | return run($query); | |
| 49 | ||
| 50 | } | |
| 51 | ||
| 52 | function run($query){
| |
| 53 | global $link; | |
| 54 | ||
| 55 | if(mysqli_query($link, $query)) return true; | |
| 56 | else return false; | |
| 57 | # code... | |
| 58 | ||
| 59 | } | |
| 60 | ||
| 61 | function excerpt($string){
| |
| 62 | $string = substr($string, 0, 10); | |
| 63 | return $string . "...."; | |
| 64 | } | |
| 65 | //============================================== | |
| 66 | require_once "view/header.php"; | |
| 67 | ||
| 68 | ||
| 69 | $articles = tampilkan(); | |
| 70 | ||
| 71 | ||
| 72 | if (isset($_GET['cari'])) {
| |
| 73 | $cari = $_GET['cari']; | |
| 74 | $articles = hasil_cari($cari); | |
| 75 | # code... | |
| 76 | } | |
| 77 | ||
| 78 | ?> | |
| 79 | ||
| 80 | <form action="" method="get"> | |
| 81 | <input type="search" name="cari" placeholder="Search"> | |
| 82 | ||
| 83 | </form> | |
| 84 | ||
| 85 | <nav class="black " role="navigation"> | |
| 86 | <div class="nav-wrapper container"> | |
| 87 | <a id="logo-container" href="#" class="brand-logo">Logo</a> | |
| 88 | <ul class="right hide-on-med-and-down"> | |
| 89 | <li><a href="index.php">Home</a></li> | |
| 90 | </ul> | |
| 91 | ||
| 92 | <ul id="nav-mobile" class="side-nav"> | |
| 93 | <li><a href="index.php">Home</a></li> | |
| 94 | </ul> | |
| 95 | <a href="" data-activates="nav-mobile" class="button-collapse"><i class="material-icons">Content</i></a> | |
| 96 | </div> | |
| 97 | </nav> | |
| 98 | ||
| 99 | ||
| 100 | <?php | |
| 101 | while($row=mysqli_fetch_assoc($articles)): ?> | |
| 102 | ||
| 103 | <div class="each_article"> | |
| 104 | <h3><a href="single.php?id=<?php echo $row['id'];?>"><?php echo $row['judul']; ?></a></h3> | |
| 105 | <p> | |
| 106 | <?php echo excerpt($row['isi']); ?> | |
| 107 | </p> | |
| 108 | <p class="waktu">Post : <?php echo $row['waktu']; ?></p> | |
| 109 | <p class="tag"> Tag : <?php echo $row['tag']; ?></p> | |
| 110 | <a href="edit.php?id=<?php echo $row['id']; ?>">Edit</a> | |
| 111 | <a href="delete.php?id=<?php echo $row['id']; ?>">Delete</a> | |
| 112 | ||
| 113 | </div> | |
| 114 | <?php endwhile; ?> | |
| 115 | ||
| 116 | ||
| 117 | <?php | |
| 118 | require_once "view/footer.php"; | |
| 119 | ?> |