<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <title>Program Sistem Pakar Diagnosa</title>
    <link href="assets/css/yeti-bootstrap.min.css" rel="stylesheet"/>
    <link href="assets/css/general.css" rel="stylesheet"/>
    <link href="assets/css/select2.min.css" rel="stylesheet"/>
    <script src="assets/js/jquery.min.js"></script>
    <script src="assets/js/bootstrap.min.js"></script>    
    <script src="assets/js/select2.min.js"></script>   
    <style type="text/css">
      .hi {
        background-image: linear-gradient(rgba(0, 0, 0, 0.5),rgba(0, 0, 0, 0.5)), url('vitaminbg.png');
        background-size: cover;
        background-position: center center;
        background-repeat: no-repeat;
        background-attachment: fixed;
      }
      .dark {
        background-color: #000;
        color: #fff;
      }
      .media img {
        border-radius: 10px;
      }
      .media-heading {
        font-size: 1.5em;
        margin-bottom: 10px;
      }
      .entry-body {
        padding: 20px;
      }
      .article-link {
        text-decoration: none;
        color: inherit;
      }
      .article-link:hover {
        text-decoration: underline;
      }
    </style>      
  </head>
  <body class="dark hi">
    <div class="page-header">
      <h1>Artikel</h1>
    </div>
    <div class="entry-body">

      <?php
        // Menghubungkan ke database
        include 'config/koneksi.php'; // Pastikan koneksi ke database

        // Mengambil data artikel dari tabel tb_artikel
        $query = "SELECT id_artikel, judul, konten, tanggal FROM tb_artikel ORDER BY tanggal DESC";
        $result = $db->query($query);

        // Menampilkan data artikel
        if ($result->num_rows > 0) {
          while ($row = $result->fetch_assoc()) {
            $id_artikel = $row['id_artikel'];
            $judul = $row['judul'];
            $konten = substr($row['konten'], 0, 200) . '...'; // Menampilkan konten singkat
            $tanggal = $row['tanggal'];
            echo '
              <div class="media">
                <div class="media-body">
                  <h4 class="media-heading"><b><a class="article-link" href="?m=artikel_detail&id_artikel=' . $id_artikel . '">' . $judul . '</a></b></h4>
                  <p>' . $konten . '</p>
                  <p><small>' . $tanggal . '</small></p>
                </div>
              </div>';
          }
        } else {
          echo '<p>Tidak ada artikel yang tersedia.</p>';
        }

        
      ?>

    </div>
  </body>
</html>
