Tugas Pertemuan 14 PWEB
Nama : Moh. Rizky Rahmadian Makkani
NRP : 5025231035
Kelas : PWEB E
Tugas Pertemuan 14 : PWEB
Perubahan dan penambahan file code baru untuk tugas pertemuan 14 tertera di bawah :
Output :
list-siswa.php
<?php include("config.php"); ?>
<!DOCTYPE html>
<html>
<head>
<title>Pendaftaran Siswa Baru | SMK Coding</title>
</head>
<body>
<style>
body, h3, table, th, td, a, p {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
}
/* Body style */
body {
background-color: #f9f9f9;
color: #333;
padding: 20px;
}
/* Header style */
header {
background-color: #007acc;
color: #fff;
text-align: center;
padding: 15px 0;
border-radius: 10px;
margin-bottom: 20px;
}
header h3 {
font-size: 1.5em;
}
/* Navigation link style */
nav a {
display: inline-block;
padding: 10px 20px;
background-color: #28a745;
color: #fff;
border-radius: 5px;
text-decoration: none;
margin-bottom: 20px;
}
nav a:hover {
background-color: #218838;
}
.btn-primary {
background-color: #28a745;
color: #fff;
border: none;
padding: 10px 20px;
border-radius: 5px;
font-size: 1em;
cursor: pointer;
font-weight: bold;
transition: background-color 0.3s;
}
.btn-primary:hover {
background-color: #218838;
}
/* Table style */
table {
width: 100%;
border-collapse: collapse;
margin-top: 10px;
background-color: #fff;
box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);
}
th, td {
border: 1px solid #ddd;
padding: 10px;
text-align: left;
}
th {
background-color: #007acc;
color: #fff;
text-transform: uppercase;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
tr:hover {
background-color: #f1f8ff;
}
/* Action links style */
a {
color: #007acc;
text-decoration: none;
font-weight: bold;
}
a:hover {
color: #005fa3;
}
/* Footer style */
p {
margin-top: 10px;
font-size: 14px;
text-align: center;
color: #555;
}
</style>
<header>
<h3>Siswa yang sudah mendaftar</h3>
</header>
<nav>
<a href="form-daftar.php">[+] Tambah Baru</a>
<form action="cetak-pdf.php" method="post">
<button type="submit" class="btn-primary">Buat Laporan</button>
</form>
</nav>
<br>
<table border="1">
<thead>
<tr>
<th>No</th>
<th>Nama</th>
<th>Alamat</th>
<th>Jenis Kelamin</th>
<th>Agama</th>
<th>Sekolah Asal</th>
<th>Nama Pegawai</th>
<th>foto</th>
<th>Tindakan</th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT calon_siswa.*, karyawan.nama nama_pegawai
FROM calon_siswa
JOIN karyawan ON calon_siswa.id_karyawan = karyawan.id";
$query = mysqli_query($db, $sql);
while($siswa = mysqli_fetch_array($query)){
echo "<tr>";
echo "<td>".$siswa['id']."</td>";
echo "<td>".$siswa['nama']."</td>";
echo "<td>".$siswa['alamat']."</td>";
echo "<td>".$siswa['jenis_kelamin']."</td>";
echo "<td>".$siswa['agama']."</td>";
echo "<td>".$siswa['sekolah_asal']."</td>";
echo "<td>".$siswa['nama_pegawai']."</td>";
if (!empty($siswa['foto'])) {
echo "<td><img src='crud_upload/images/".$siswa['foto']."' alt='Foto Siswa' style='max-width: 100px; height: auto;'></td>";
} else {
echo "<td><em>Tidak ada foto</em></td>";
}
echo "<td>";
echo "<a href='form-edit.php?id=".$siswa['id']."'>Edit</a> | ";
echo "<a href='hapus.php?id=".$siswa['id']."'>Hapus</a>";
echo "</td>";
echo "</tr>";
}
?>
</tbody>
</table>
<p>Total: <?php echo mysqli_num_rows($query) ?></p>
</body>
</html>
cetak-pdf.php
<?php
// Start output buffering to prevent any accidental output
ob_start();
// Include configuration file (ensure this file does not output anything)
include("config.php");
// Include the FPDF library
require('fpdf186/fpdf.php');
// Create a new FPDF instance and set up the page
$pdf = new FPDF('L', 'mm', 'A4');
$pdf->AddPage();
// Set the font for the header
$pdf->SetFont('Arial', 'B', 16);
$pdf->Cell(190, 7, 'LAPORAN CALON SISWA SMK CODING', 0, 1, 'C');
$pdf->SetFont('Arial', 'B', 12);
$pdf->Cell(190, 7, 'DAFTAR SISWA P WEB CODING TAHUN 2024', 0, 1, 'C');
// Add a space below the title
$pdf->Cell(10, 7, '', 0, 1);
// Set font for the table header
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(20, 6, 'ID SISWA', 1, 0, 'C');
$pdf->Cell(48, 6, 'NAMA SISWA', 1, 0, 'C');
$pdf->Cell(53, 6, 'ALAMAT SISWA', 1, 0, 'C');
$pdf->Cell(60, 6, 'JENIS KELAMIN', 1, 0, 'C');
$pdf->Cell(73, 6, 'SEKOLAH ASAL SISWA', 1, 1, 'C');
// Set font for the table data
$pdf->SetFont('Arial', '', 10);
// Query to fetch data from the database
$mahasiswa = mysqli_query($db, "SELECT * FROM calon_siswa");
// Loop through the data and add it to the PDF
while ($row = mysqli_fetch_array($mahasiswa)) {
$pdf->Cell(20, 6, $row['id'], 1, 0, 'C');
$pdf->Cell(48, 6, $row['nama'], 1, 0);
$pdf->Cell(53, 6, $row['alamat'], 1, 0);
$pdf->Cell(60, 6, $row['jenis_kelamin'], 1, 0);
$pdf->Cell(73, 6, $row['sekolah_asal'], 1, 1);
}
// End output buffering and clean any output before generating the PDF
ob_end_clean();
// Output the PDF
$pdf->Output();
?>
Komentar
Posting Komentar