From d9537446b3b92ab5b546d6c9295792fd6cd31e45 Mon Sep 17 00:00:00 2001 From: Fluffy-Bean Date: Thu, 28 Jul 2022 11:35:57 +0100 Subject: [PATCH] Cleaned up code on image details screen --- image.php | 80 +++++++++++++++++++++++++++---------------------------- 1 file changed, 39 insertions(+), 41 deletions(-) diff --git a/image.php b/image.php index 0625299..d5a0e26 100644 --- a/image.php +++ b/image.php @@ -14,7 +14,6 @@ include("ui/header.php"); include_once("ui/conn.php"); - // Update toast if ($_GET["update"] == "success") { echo "

Information updated

"; @@ -22,61 +21,57 @@ echo "

No alt, skip

"; } - // Getting all image info from table - $get_image = "SELECT * FROM swag_table WHERE id = ".$_GET['id']; - $image_results = mysqli_query($conn, $get_image); - $image = mysqli_fetch_assoc($image_results); + // If ID present pull all image data + if (isset($_GET['id'])) { + $get_image = "SELECT * FROM swag_table WHERE id = ".$_GET['id']; + $image_results = mysqli_query($conn, $get_image); + $image = mysqli_fetch_assoc($image_results); - // Get all user details - if (isset($image['author'])) { - $get_user = "SELECT * FROM users WHERE id = ".$image['author']; - $user_results = mysqli_query($conn, $get_user); - $user = mysqli_fetch_assoc($user_results); - } + // Check if image is avalible + if (isset($image['imagename'])) { + // Display image + $image_path = "images/".$image['imagename']; + $image_alt = $image['alt']; + } else { + // ID not avalible toast + echo "

Could not find image with ID: ".$_GET['id']."

"; - // Check if ID of image in URL - if (empty($_GET['id'])) { + // Replacement "no image" image and description + $image_path = "assets/no_image.png"; + $image_alt = "No image could be found, sowwy"; + } + } else { // No ID toast echo "

No ID present

"; // Replacement "no image" image and description $image_path = "assets/no_image.png"; $image_alt = "No image could be found, sowwy"; - - } elseif (empty($image['imagename'])) { - // ID not avalible toast - echo "

Could not find image with ID: ".$_GET['id']."

"; - - // Replacement "no image" image and description - $image_path = "assets/no_image.png"; - $image_alt = "No image could be found, sowwy"; - - } else { - // Display image - $image_path = "images/".$image['imagename']; - $image_alt = $image['alt']; - - // Add image view - if (empty($image['views'])) { - //$conn->query("UPDATE swag_table SET views=1 WHERE id=".$image['id']); - } else { - //$conn->query("UPDATE swag_table SET views=views+1 WHERE id=".$image['id']); - } } + + // Get all user details + if (isset($image['author'])) { + $get_user = "SELECT * FROM users WHERE id = ".$image['author']; + $user_results = mysqli_query($conn, $get_user); + $user = mysqli_fetch_assoc($user_results); + } else ?>
- "; ?> + "; + ?>

Description

No description provided

"; - }else{ + if (isset($image_alt)) { echo "

".$image_alt."

"; + } else { + echo "

No description provided

"; } ?>
@@ -86,14 +81,15 @@ Author: ".$user['username']."

"; + if (isset($user['username'])) { + echo "

Author: ".$user['username']."

"; + } else { + echo "

Author: Deleted User

"; + } } else { echo "

Author: No author

"; } - // Views - //echo "

Views: ".$image['views']."

"; - // Image ID echo "

ID: ".$image['id']."

"; @@ -113,6 +109,7 @@ "; echo "

Danger zone

"; + // Image hover details echo "
"; echo "";