Created
January 24, 2024 04:03
-
-
Save ihsanfaisal/5c36d52dde8d6ce79d6ede7f3e85f709 to your computer and use it in GitHub Desktop.
Daftar pelanggan
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 1. buka koneksi ke database | |
$host = "localhost"; | |
$user = "root"; | |
$password = ""; | |
$database = "dbkasir100"; | |
$dsn = "mysql:host=$host;dbname=$database;charset=UTF8"; | |
try { | |
$pdo = new PDO($dsn, $user, $password); | |
if ($pdo) { | |
// echo "Berhasil terhubung ke data base $database!"; | |
} | |
} catch (PDOException $e) { | |
echo $e->getMessage(); | |
} | |
// 2. buat sql ambil data | |
$sql = "SELECT * FROM pelanggan"; | |
// 3. execute sql | |
$statement = $pdo->query($sql); | |
$daftarpelanggan = $statement->fetchAll(PDO::FETCH_ASSOC); | |
// var_dump($daftarpelanggan); | |
// 4. tampilkan di html | |
?> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=\, initial-scale=1.0"> | |
<title>Daftar Pelanggan</title> | |
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous"> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script> | |
</head> | |
<body class="m-4"> | |
<h1>Daftar Pelanggan</h1> | |
<table class="table"> | |
<thead> | |
<tr> | |
<th scope="col">No</th> | |
<th scope="col">Nama Pelanggan</th> | |
<th scope="col">Alamat</th> | |
<th scope="col">Telepon</th> | |
</tr> | |
</thead> | |
<tbody> | |
<?php | |
$nomor = 1; | |
foreach ($daftarpelanggan as $pelanggan) { | |
?> | |
<tr> | |
<th scope="row"><?php echo $nomor ?></th> | |
<td><?php echo $pelanggan['namapelanggan'] ?></td> | |
<td><?php echo $pelanggan['alamat'] ?></td> | |
<td><?php echo $pelanggan['nomortelepon'] ?></td> | |
</tr> | |
<?php | |
$nomor++; | |
} | |
?> | |
</tbody> | |
</table> | |
<a href="menu.php">Kembali ke Menu</a> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment