Pārlūkot izejas kodu

initial activity request and selection

Sebastian Vendt 5 mēneši atpakaļ
vecāks
revīzija
5f96b2871b
1 mainītis faili ar 72 papildinājumiem un 0 dzēšanām
  1. 72 0
      index.php

+ 72 - 0
index.php

@@ -0,0 +1,72 @@
+<?php
+// Include the external configuration file
+require_once '../config.php';
+
+// error reporting
+error_reporting(E_ALL);
+
+try {
+    // Use the settings from config.php for the PDO connection
+    $pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
+    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+} catch (PDOException $e) {
+    echo 'Connection failed: ' . $e->getMessage();
+    exit;
+}
+
+// Query to fetch activities and their corresponding names
+$query = "
+    SELECT a.activityID, an.activityName
+    FROM activities a
+    JOIN activity_names an ON a.activityID = an.activityID
+";
+
+// Execute the query and fetch the results
+$stmt = $pdo->query($query);
+$activities = $stmt->fetchAll(PDO::FETCH_ASSOC);
+
+// If no activities found
+if (!$activities) {
+    echo "No activities found.";
+    exit;
+}
+?>
+
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Activity Selection</title>
+    <style>
+        body {
+            font-family: Arial, sans-serif;
+            padding: 20px;
+        }
+        .category-item {
+            margin: 5px 0;
+        }
+        .category-item input {
+            margin-right: 10px;
+        }
+    </style>
+</head>
+<body>
+
+    <h1>Select Activities</h1>
+    <form action="submit_activities.php" method="GET">
+        <?php foreach ($activities as $activity): ?>
+            <div class="activity-item">
+                <input type="checkbox" name="activity_ids[]" value="<?php echo htmlspecialchars($activity['activityID']); ?>">
+                <label for="category_<?php echo htmlspecialchars($activity['activityID']); ?>">
+                    <?php echo htmlspecialchars($activity['activityName']); ?>
+                </label>
+            </div>
+        <?php endforeach; ?>
+
+        <br>
+        <button type="submit">Submit</button>
+    </form>
+
+</body>
+</html>