From 7d516df61b8951989db3247ca2daca3b69d52393 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Thu, 18 Sep 2025 12:18:42 +0000 Subject: [PATCH] beautiful results --- assets/js/main.js | 7 -- results.php | 158 ++++++++++++++++++++++++++++------------------ 2 files changed, 97 insertions(+), 68 deletions(-) diff --git a/assets/js/main.js b/assets/js/main.js index 3d1134e..b8801c0 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -37,13 +37,6 @@ document.addEventListener('DOMContentLoaded', function () { event.preventDefault(); const formData = new FormData(form); const data = Object.fromEntries(formData.entries()); - const votes = (data.category === 'beauty') ? beautyVotes : funnyVotes; - - // Add the individual vote numbers to the data object for the backend - data.website_number_1 = votes[0] || ''; - data.website_number_2 = votes[1] || ''; - data.website_number_3 = votes[2] || ''; - delete data.website_numbers; // remove the comma-separated string fetch('submit_vote.php', { method: 'POST', diff --git a/results.php b/results.php index 1aab1f0..4f0c0d4 100644 --- a/results.php +++ b/results.php @@ -13,8 +13,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $pdo = db(); $pdo->exec('TRUNCATE TABLE votes'); $message = 'All votes have been cleared.'; - } - else { + } else { if (!isset($_SESSION['loggedin']) || !$_SESSION['loggedin']) { $error = 'Invalid password'; } @@ -26,67 +25,104 @@ if (isset($_GET['logout'])) { header('Location: results.php'); exit; } +?> + + + + + + Voting Results + + + + +
+ +
+

Voting Results

+ Logout +
-if (isset($_SESSION['loggedin']) && $_SESSION['loggedin']) { - // Display results - echo '

Voting Results

'; - if ($message) { - echo "

$message

"; - } - // Database connection - require_once 'db/config.php'; - $pdo = db(); + +
+ - // Fetch results - $stmt = $pdo->query('SELECT category, website_number, COUNT(*) as votes FROM votes GROUP BY category, website_number ORDER BY category, votes DESC'); - $results = $stmt->fetchAll(PDO::FETCH_ASSOC); +
+
+
+
+

Most Beautiful Website

+ query("SELECT website_number, COUNT(*) as votes FROM votes WHERE category = 'beauty' GROUP BY website_number ORDER BY votes DESC"); + $results = $stmt->fetchAll(PDO::FETCH_ASSOC); + if (empty($results)): ?> +

No votes yet.

+ +
    + +
  • + Website + votes +
  • + +
+ +
+
+
+
+
+
+

Most Funny/Interesting Website

+ query("SELECT website_number, COUNT(*) as votes FROM votes WHERE category = 'funny' GROUP BY website_number ORDER BY votes DESC"); + $results = $stmt->fetchAll(PDO::FETCH_ASSOC); + if (empty($results)): ?> +

No votes yet.

+ +
    + +
  • + Website + votes +
  • + +
+ +
+
+
+
- echo '

Most Beautiful Website

'; - echo ''; +
+
+ +
+
- echo '

Most Funny/Interesting Website

'; - echo ''; - - echo '
'; - echo '
Logout'; - -} else { - // Display password form - ?> - - - - View Results - - -

Enter Password to View Results

-
- - -
- -

+ +
+
+
+
+

View Results

+
+
+ + +
+ + +

+ +
+
+
+
+
- - - \ No newline at end of file +
+ +