<?php
include "koneksi.php";

$query = mysqli_query($conn, "SELECT * FROM kegiatan");

if (!$query) {
    die("Query error: " . mysqli_error($conn));
}
?>


<!DOCTYPE html>
<html>
<head>
    <title>Kegiatan Pondok Pesantren</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>

<h2 style="text-align:center;margin:40px 0">Kegiatan Pondok Pesantren</h2>

<div style="display:flex;flex-wrap:wrap;gap:20px;justify-content:center">

<?php if (mysqli_num_rows($query) > 0) { ?>
    <?php while ($row = mysqli_fetch_assoc($query)) { ?>
        <div style="width:300px;background:rgba(255,255,255,0.1);border-radius:12px;overflow:hidden">
            <img src="uploads/kegiatan/<?php echo $row['foto']; ?>"
                 style="width:100%;height:200px;object-fit:cover">

            <div style="padding:15px">
                <h3><?php echo $row['judul']; ?></h3>
                <p style="font-size:14px;opacity:0.85">
                    <?php echo substr($row['deskripsi'], 0, 100); ?>...
                </p>
            </div>
        </div>
    <?php } ?>
<?php } else { ?>
    <p>Belum ada kegiatan.</p>
<?php } ?>

</div>

</body>
</html>
