August 11, 2020

Mawan.my.id

Blog Mawan di DobelHost

tampil.php

<?php
	include("koneksi.php");
?>
<html>
<head>
	<title>Tampil</title>
	<link rel="stylesheet" type="text/css" href="gaya.css">
</head>

<body>
<?php
	include('menu.php');

	// Melakukan quary ke tabel.
	$stmt = $pdo->query('SELECT * FROM tugas1');

	echo '<p>Menampilkan semua record</p>';

	echo '<table class="tabel">';
	echo '<tr>';
	echo '<th>Username</th>';
	echo '<th>Password (md5)</th>';
	echo '<th>Nama lengkap</th>';
	echo '<th>Tanggal lahir</th>';
	echo '<th>Nilai</th>';
	echo '</td>';

	// Tampilkan setiap data yang terpilih hasil dari query di atas.
	while ($row = $stmt->fetch()) {
		echo '<tr>';
		echo '<td>'. $row['username'] . '</td>';
		echo '<td>'. $row['password'] . '</td>';
		echo '<td>'. $row['nama'] . '</td>';
		echo '<td>'. $row['lahir'] . '</td>';
		echo '<td>'. $row['nilai'] . '</td>';
		echo '</tr>';
	};

	echo '</table>';
?>
</body>
</html>

Bila anda bingung memahami baris 29, kode di baris 29 sampai 37 bisa dijabarkan menjadi:

	// Tampilkan setiap data yang terpilih hasil dari query di atas.
	$row = $stmt->fetch();
	while ($row != FALSE) {
		echo '<tr>';
		echo '<td>'. $row['username'] . '</td>';
		echo '<td>'. $row['password'] . '</td>';
		echo '<td>'. $row['nama'] . '</td>';
		echo '<td>'. $row['lahir'] . '</td>';
		echo '<td>'. $row['nilai'] . '</td>';
		echo '</tr>';
		$row = $stmt->fetch();
	};

Nah, sekarang jadi lebih mudah dipahami kan?

Leave a Reply

Your email address will not be published. Required fields are marked *