Untitled

mail@pastecode.io avatar
unknown
plain_text
19 days ago
1.5 kB
1
Indexable
Never
<?php
include "koneksi.php"; // memanggil koneksi.php agar bisa memanggil data dari database

$sql = mysqli_query($koneksi, "SELECT * FROM barang");
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CRUD - Index</title>
</head>
<body>
    <h2>Barang List</h2>
    
    <table border="1">
        <tr>
            <th>ID Barang</th>
            <th>Nama User</th>
            <th>Stok</th>
            <th>Harga</th>
            <th>Actions</th>
        </tr>
        <?php  // membuat fungsi untuk menampilkan data dari database
        if ($sql->num_rows > 0) {
            while ($row = $sql->fetch_assoc()) {
                echo "<tr>
                        <td>" . $row['id_brg'] . "</td> 
                        <td>" . $row['nama_brg'] . "</td>
                        <td>" . $row['stok'] . "</td>
                        <td>" . $row['harga'] . "</td>
                        <td>
                            <a href='update.php?id=" . $row['id_brg'] . "'>Edit</a> |
                            <a href='delete.php?id=" . $row['id_brg'] . "' onclick='return confirm(\"Are you sure?\")'>Delete</a>
                        </td>
                      </tr>";
            }
        } else {
            echo "<tr><td colspan='4'>No users found</td></tr>";
        }
        ?>
    </table>
</body>
</html>

<?php
// Tutup koneksi database
$koneksi->close();
?>
Leave a Comment