Add past event section
This commit is contained in:
46
index.php
46
index.php
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Allmende-Essen</title>
|
||||
<title>Allmende-Essen Test</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
@@ -109,8 +109,8 @@
|
||||
$dsn = "pgsql:host=$host;dbname=$dbname";
|
||||
$pdo = new PDO($dsn, $username, $password);
|
||||
|
||||
// Query to fetch dinner options
|
||||
$sql = "SELECT id, title, link, event_date, registration_closes FROM meals order by registration_closes < now(), event_date";
|
||||
// Query to fetch future dinner options
|
||||
$sql = "SELECT id, title, link, event_date, registration_closes FROM meals WHERE event_date >= now()::date order by registration_closes < now(), event_date";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute();
|
||||
|
||||
@@ -126,12 +126,9 @@
|
||||
<?php // Display dinner options
|
||||
for($i = 0; $i < sizeof($result); $i++) {
|
||||
$row = $result[$i];
|
||||
|
||||
|
||||
$event_date = strtotime($row["event_date"]);
|
||||
|
||||
if ($event_date < $today) {
|
||||
continue;
|
||||
}
|
||||
$weekday = date("w", $event_date);
|
||||
$date = new DateTimeImmutable($row["event_date"]);
|
||||
|
||||
@@ -146,9 +143,42 @@
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
// close container
|
||||
echo '</div>';
|
||||
|
||||
// Query to fetch past dinner options
|
||||
$sql = "SELECT id, title, link, event_date FROM meals WHERE event_date < now()::date order by event_date";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute();
|
||||
|
||||
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
if(sizeof($result) > 0) {
|
||||
?>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
<h2>Vergangene Essen</h2>
|
||||
|
||||
<?php
|
||||
for($i = 0; $i < sizeof($result); $i++) {
|
||||
$row = $result[$i];
|
||||
|
||||
$event_date = strtotime($row["event_date"]);
|
||||
|
||||
$weekday = date("w", $event_date);
|
||||
$date = new DateTimeImmutable($row["event_date"]);
|
||||
|
||||
echo '<div class="dinner-option">';
|
||||
echo '<h2>' . $days[$weekday] . " " . $date->format('d.m.Y') .'</h2>';
|
||||
echo '<p>' . htmlspecialchars($row["title"]) . '</p>';
|
||||
echo '<a href="' . $row["link"] . '" class="btn btn-grey">Anmeldungen ansehen</a>';
|
||||
echo '</div>';
|
||||
}
|
||||
// close container
|
||||
echo '</div>';
|
||||
}
|
||||
?>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user