Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- try {
- $db=new PDO('mysql:host=localhost;dbname=latihan', "root", "kucing");
- $sql = $db->prepare("SELECT * FROM barang");
- if($sql->execute()){
- $sql->setFetchMode(PDO::FETCH_ASSOC);
- }
- // $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- } catch (Exception $error) {
- echo '<p>', $error->getMessage(), '</p>';
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewpoint" content="width=device-width, initial-scale=1">
- <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
- <script src="bootstrap/js/jquery-2.4.1.min.js"></script>
- <script src="bootstrap/js/bootstrap.min.js"></script>
- <style>
- h1{text-align:center;}
- table{style="float:right" border"1"}
- </style>
- <title>Tampilkan Data</title>
- </head>
- <body>
- <div class="container">
- <h1>Menampilkan Isi Tabel MySQL</h1>
- <table class="table">
- <thead>
- <tr>
- <th>ID Barang</th>
- <th>Nama Barang</th>
- <th>Harga Satuan</th>
- </tr>
- </thead>
- <tbody>
- <?php while($row = $sql->fetch()) { ?>
- <tr>
- <td><?php echo $row["idbarang"]; ?></td>
- <td><?php echo $row["namabarang"]; ?></td>
- <td><?php echo $row["hargasatuan"]; ?></td>
- </tr>
- <?php } ?>
- </tbody>
- </table>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement