<?php include('config.php'); ?>

<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <title>Toko Sembako</title>
    <link rel="stylesheet" href="style.css">
    <script src="script.js" defer></script>
</head>
<body>
    <h1>Toko Sembako</h1>
    <a href="profil.php">Profil Usaha</a>
    <a href="tambah.php">Tambah Barang</a>
    <table>
        <tr>
            <th>No</th>
            <th>Nama Barang</th>
            <th>Jenis Barang</th>
            <th>Harga</th>
            <th>Stok</th>
            <th>Aksi</th>
        </tr>
        <?php
        $result = mysqli_query($conn, "SELECT * FROM barang");
        $no = 1;
        while ($data = mysqli_fetch_assoc($result)) {
            echo "<tr>
                    <td>{$no}</td>
                    <td>{$data['nama_barang']}</td>
                    <td>{$data['jenis_barang']}</td>
                    <td>{$data['harga_barang']}</td>
                    <td>{$data['stok_barang']}</td>
                    <td>
                        <a href='edit.php?id={$data['id']}'>Edit</a> |
                        <a href='delete.php?id={$data['id']}' onclick='return confirmDelete()'>Hapus</a>
                    </td>
                  </tr>";
            $no++;
        }
        ?>
    </table>
</body>
</html>
