<?php
$connect = new mysqli('localhost', 'root',  '', 'clubhub','3306');


if($connect -> connect_error){
    $error_type = $connect->connect_error;
    echo "<script>var error = '$error_type';</script>";
    echo '<script>alert("Database Connection Failed: " + error);</script>';
    die("failed");
}


$sql = 'SELECT name, post, description, time, date, place FROM ACT_POST';
$result = mysqli_query($connect, $sql) or die( mysqli_error($connect));


// fetch the resulting rows as an array
$clubs = mysqli_fetch_all($result, MYSQLI_ASSOC);

// free the $result from memory (good practise)
mysqli_free_result($result);

// close connection
mysqli_close($connect);


?>








<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>Directory - TheClubHub</title>
  <link rel="icon" type="image/x-icon" href="/images/favicon.ico">

  <meta name="viewport" content="width=device-width">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
  <link href="style.css" rel="stylesheet" type="text/css" />
</head>

<head>
<link type="text/css" rel="stylesheet" href="css/materialize.min.css"  media="screen,projection"/>

</head>

<body>

<div class="header">
    <header>
      <h1><a href="activities.php" class="logo">CHCI Activities</a></h1>
      <nav class="navBar">
        <div class="dropdown">
          <a href="#" class="dropButton">Departments <i class="fas fa-angle-down"></i></a>
          <div class="dropdownContent">
            <a href="">Academics</a>
            <a href="">Music</a>
            <a href="">Athletics</a>
            <a href="">Art</a>
            <a href="">Entertainment</a>
            <a href="">Student Associations</a>
          </div>
        </div>
        <a href="directory.php">Directory</a>
        <a href="register.html">Register</a>
        <a href="profile.html">Profile</a>
        <a href="contact.html">Contact</a>
        <a href="settings.html">Settings</a>
        <a href="login.html">Student Login</a>
        <a href="activities.php">Student Login</a>
      </nav>
    </header>
  </div>





<div class ="club_page">
<h3 class="Title">Clubs Here at Cameron</h4>
<br>
<br>
      <?php

                foreach($clubs as $club) {
                    echo "<div class='club-info'>";
                    echo "<h2>" . htmlspecialchars($club['name']) . "</h2>";

                    if (!empty($club['post']) && filter_var($club['post'], FILTER_VALIDATE_URL)) {
                        echo "<div class='club-image'>";
                        echo "<img src='" . htmlspecialchars($club['post']) . "' alt='Club Image'>";
                        echo "</div>";
                    } else {
                        // Fallback to placeholder image
                        echo "<div class='club-image'>";
                        echo "<img src='Images/iPhone-Rigi.jpg' alt='No Image Available'>";
                        echo "</div>";
                    }
  
                    echo "<p><strong>Department:</strong> " . htmlspecialchars($club['description']) . "</p>";
                    echo "<p><strong>Room:</strong> " . htmlspecialchars($club['time']) . "</p>";
                    echo "<p><strong>Meeting Day:</strong> " . htmlspecialchars($club['date']) . "</p>";
                    echo "<p><strong>Time:</strong> " . htmlspecialchars($club['place']) . "</p>";
  


                    echo "</div>";
                }


            ?>




  </div>
</div>
</body>

</html>

