From ff5aea83d691afe7bc610311d89e8673f6950784 Mon Sep 17 00:00:00 2001 From: vista-man <524715@vistacollege.nl> Date: Thu, 27 Mar 2025 09:52:00 +0100 Subject: [PATCH] =?UTF-8?q?Add=20user=20Pok=C3=A9mon=20relationships=20tab?= =?UTF-8?q?le=20and=20improve=20error=20handling=20in=20competitors=20data?= =?UTF-8?q?=20fetching?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pokedex_database.sql | 8 ++++++++ v2/get-competitors.php | 20 +++++++++++++------- v2/style.css | 2 +- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/pokedex_database.sql b/pokedex_database.sql index b1fec94..a440ef7 100644 --- a/pokedex_database.sql +++ b/pokedex_database.sql @@ -97,3 +97,11 @@ CREATE TABLE IF NOT EXISTS pokemon_egg_groups ( FOREIGN KEY (pokemon_id) REFERENCES pokemon(id), FOREIGN KEY (egg_group_id) REFERENCES egg_groups(id) ); + +-- Table to store user Pokémon relationships +CREATE TABLE IF NOT EXISTS user_pokemon ( + user_id INT NOT NULL, + pokemon_id INT NOT NULL, + PRIMARY KEY (user_id, pokemon_id), + FOREIGN KEY (pokemon_id) REFERENCES pokemon(id) +); diff --git a/v2/get-competitors.php b/v2/get-competitors.php index c632464..4711d89 100644 --- a/v2/get-competitors.php +++ b/v2/get-competitors.php @@ -35,15 +35,21 @@ try { logMessage("Executing query: $sql"); $result = $conn->query($sql); - if ($result) { - $competitors = []; - while ($row = $result->fetch_assoc()) { - $competitors[] = $row; - } + if ($result === false) { + throw new Exception("Query failed: " . $conn->error); + } + + $competitors = []; + while ($row = $result->fetch_assoc()) { + $competitors[] = $row; + } + + if (empty($competitors)) { + logMessage("No competitors data found."); + echo json_encode(["error" => "No competitors data found"]); + } else { logMessage("Query result: " . json_encode($competitors)); echo json_encode($competitors); - } else { - throw new Exception("Error executing query: " . $conn->error); } } catch (Exception $e) { logMessage("Exception: " . $e->getMessage()); diff --git a/v2/style.css b/v2/style.css index a0b15f3..114acdb 100644 --- a/v2/style.css +++ b/v2/style.css @@ -1,5 +1,5 @@ :root { - --identity-primary: #dc0a2d; + --identity-primary: #0394fc; --grayscale-dark: #212121; --grayscale-medium: #666666;