uscode

list barang

Aug 20th, 2019
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.06 KB | None | 0 0
  1. <?php
  2. $search = isset($_GET["search"]) ? $_GET["search"] : false;
  3.  
  4. $where = "";
  5. $search_url = "";
  6. if ($search) {
  7.     $search_url = "&search=$search";
  8.     $where = "WHERE barang.nama_barang LIKE '%$search%'";
  9. }
  10. ?>
  11. <div id="frame-tambah">
  12.     <div id="left">
  13.         <form action="<?php echo BASE_URL . "index.php"; ?>" method="GET">
  14.             <input type="hidden" name="page" value="<?php echo $_GET["page"]; ?>" />
  15.             <input type="hidden" name="module" value="<?php echo $_GET["module"]; ?>" />
  16.             <input type="hidden" name="action" value="<?php echo $_GET["action"]; ?>" />
  17.             <input type="text" name="search" value="<?php echo $search; ?>" />
  18.             <input type="submit" value="Search" />
  19.         </form>
  20.     </div>
  21.     <div id="right">
  22.         <!-- button / link tambah data kategori -->
  23.         <a href="<?php echo BASE_URL . "index.php?page=my_profile&module=barang&action=form"; ?>" class="tombol-action">+ Tambah Barang</a>
  24.     </div>
  25. </div>
  26.  
  27. <?php
  28. $pagination = isset($_GET["pagination"]) ? $_GET["pagination"] : 1;
  29. $data_per_halaman = 3;
  30. $mulai_dari = ($pagination - 1) * $data_per_halaman;
  31.  
  32. // koneksi Database ke tabel
  33. $queryBarang = mysqli_query($koneksi, "SELECT barang.*, kategori.kategori FROM barang
  34.                                        JOIN kategori ON barang.kategori_id = kategori.kategori_id
  35.                                        $where LIMIT $mulai_dari, $data_per_halaman");
  36.  
  37. // check tabel per row
  38. if (mysqli_num_rows($queryBarang) == 0) {
  39.     echo "<h3>Maaf list menu belum tersedia</h3>";
  40. } else {
  41.     echo "<table class='table-list'>";
  42.  
  43.     echo "<tr class='baris-title'>
  44.                <th class='kolom-nomor'>No</th>
  45.                <th class='kiri'>Nama Barang</th>
  46.                <th class='tengah'>kategori</th>
  47.                <th class='tengah'>Harga</th>
  48.                <th class='tengah'>Status</th>
  49.                <th class='tengah'>action</th>
  50.            </tr>";
  51.     $no = 1 + $mulai_dari;
  52.     //melakukan perulangan dan mengeluarkan data table kategori ke dalam list tabel
  53.     while ($row = mysqli_fetch_assoc($queryBarang)) {
  54.         echo "<tr>
  55.                <td class='kolom-nomor'>$no</td>
  56.                <td class='kiri'>$row[nama_barang]</td>
  57.                <td class='tengah'>$row[kategori]</td>
  58.                <td class='tengah'>" . rupiah($row["harga"]) . "</td>
  59.                <td class='tengah'>$row[status]</td>
  60.                <td class='tengah'>
  61.                    <a class='tombol-action' href='" . BASE_URL . "index.php?page=my_profile&module=barang&action=form&barang_id=$row[barang_id]'>Edit</a>
  62.                    <a class='tombol-action' href='" . BASE_URL . "module/barang/action.php?button=delete&barang_id=$row[barang_id]'>Delete</a>
  63.                </td>              
  64.                </tr>";
  65.         $no++;
  66.     }
  67.     echo "</table>";
  68.  
  69.     $queryHitungBarang = mysqli_query($koneksi, "SELECT * FROM barang");
  70.     pagination($queryHitungBarang, $data_per_halaman, $pagination, "index.php?page=my_profile&module=barang&action=list$search_url");
  71. }
  72. ?>
Advertisement
Add Comment
Please, Sign In to add comment