Anda di halaman 1dari 2

MENAMPILKAN DATA/FUNCTION

1. Index.php
<?php
require 'function.php';

$siswa = query("SELECT * FROM siswa")


?>
<html>
<head>
<title> HAlaman Admin </title>
</head>
<body>
<h1> Daftar Siswa </h1>
<table border="1" cellpadding="10" cellspacing="0">
<tr>
<th> No </th>
<th> Nama </th>
<th> Nis </th>
<th> Email </th>
<th> Jurusan </th>
<th> Foto </th>
<th> Aksi </th>
</tr>
<?php $i=1; ?>
<?php foreach($siswa as $row) :?>

<tr>
<td> <?= $i; ?> </td>
<td><?= $row["nama"]; ?> </td>
<td><?= $row["nis"]; ?></td>
<td><?= $row["email"]; ?> </td>
<td><?= $row["jurusan"]; ?> </td>
<td><img src="img/<?php echo $row["gambar"]; ?>" width="50"> </td>
<td>
<a href= ""> edit</a>
<a href= ""> edit</a>
</td>
</tr>
<?php $i++; ?>
<?php endforeach; ?>
</table>
</body>
</html>

1|menampilkan da ta function
2. Function
<?php
//koneksi database
$connect = mysqli_connect("localhost", "root", "", "sekolah");

function query($query){
global $connect;
$result = mysqli_query($connect, $query);
$rows = [];
while ($row = mysqli_fetch_assoc($result)){
$rows[] = $row;
}
return $rows;
}

?>

2|menampilkan da ta function

Anda mungkin juga menyukai