From 685c05242872924d062c28247e0400c0307b9ee4 Mon Sep 17 00:00:00 2001 From: snowflake Date: Thu, 10 Feb 2022 13:15:49 +0100 Subject: [PATCH] deleting crumbles --- beer.php | 9 +++- controller/listLatest.php | 81 ++++++++++++++++++++++++++++++++-- search.php | 91 ++++++++++++++++++++++++++++++++++++++- view/sidebar.php | 8 ++-- 4 files changed, 180 insertions(+), 9 deletions(-) diff --git a/beer.php b/beer.php index 8706a56..b47e792 100644 --- a/beer.php +++ b/beer.php @@ -18,10 +18,14 @@ $brewery_id = $record["brewery_id"]; $brewery = getRecord($pdo, "brewery", $brewery_id )["name"]; require("view/mainContent/mainContent.php"); require("view/mainContent/beerExtraInfo.php"); + +echo "
+
+
"; + if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true){ if(isThisBound($pdo, "list", $_GET["id"], $_SESSION["id"])){ $rating = getRating( $pdo, $_GET["id"], $_SESSION["id"])["rating"]; - showStars($_GET["id"], $rating); unfollowButton("list", $_GET["id"]); } else { @@ -29,6 +33,9 @@ if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true){ } } +echo "
+
+
"; $array = listTagsByBeer($pdo, $_GET["id"]); diff --git a/controller/listLatest.php b/controller/listLatest.php index e4180d4..ba9e458 100644 --- a/controller/listLatest.php +++ b/controller/listLatest.php @@ -83,7 +83,7 @@ function listTagsByBeer($pdo, $beer){ return $arrayBeersXTags; } -function listBeersByTag($pdo, $tag){ +function listBeersByTagID($pdo, $tag){ $conn = $pdo; try { @@ -112,7 +112,7 @@ function listBeersByUser($pdo, $user){ return $arrayOfBeers; } -function listBeersByBreweryNAN( $pdo ){ +function listBreweriesNAN( $pdo ){ $conn = $pdo; try { $sql = "SELECT * FROM brewery"; @@ -124,4 +124,79 @@ function listBeersByBreweryNAN( $pdo ){ echo "Error in Breweries: " . $e->getMessage(); } return $arrayOfBreweries; -} \ No newline at end of file +} + +function listBeersNAN( $pdo ){ + $conn = $pdo; + try { + $sql = "SELECT * FROM beer"; + $stmt = $conn->prepare($sql); + $stmt->execute(); + $result = $stmt->setFetchMode(PDO::FETCH_ASSOC); + $arrayOfBreweries = $stmt->fetchAll(); + } catch (PDOException $e) { + echo "Error in Breweries: " . $e->getMessage(); + } + return $arrayOfBreweries; +} + +function listBeersByTag($pdo, $tag){ + $conn = $pdo; + try { + + $stmt = $conn->prepare("SELECT * FROM beer_has_tag JOIN tag ON tag_id WHERE tag_title LIKE $tag"); + $stmt->execute(); + $result = $stmt->setFetchMode(PDO::FETCH_ASSOC); + $arrayTagsXBeers = $stmt->fetchAll(); + } catch (PDOException $e) { + echo "Error in Beers: " . $e->getMessage(); + } + print_r($arrayTagsXBeers); + return $arrayTagsXBeers; +} + +function listBeersByName($pdo, $name){ + $conn = $pdo; + try { + + $stmt = $conn->prepare("SELECT * FROM beer WHERE name LIKE $name"); + $stmt->execute(); + $result = $stmt->setFetchMode(PDO::FETCH_ASSOC); + $arrayTagsXBeers = $stmt->fetchAll(); + } catch (PDOException $e) { + echo "Error in Beers: " . $e->getMessage(); + } + print_r($arrayTagsXBeers); + return $arrayTagsXBeers; +} + +function listBreweryByName($pdo, $name){ + $conn = $pdo; + try { + + $stmt = $conn->prepare("SELECT * FROM brewery WHERE name LIKE $name"); + $stmt->execute(); + $result = $stmt->setFetchMode(PDO::FETCH_ASSOC); + $arrayTagsXBeers = $stmt->fetchAll(); + } catch (PDOException $e) { + echo "Error in Beers: " . $e->getMessage(); + } + print_r($arrayTagsXBeers); + return $arrayTagsXBeers; +} + + +function listArticleByName($pdo, $title){ + $conn = $pdo; + try { + + $stmt = $conn->prepare("SELECT * FROM article WHERE title LIKE $title"); + $stmt->execute(); + $result = $stmt->setFetchMode(PDO::FETCH_ASSOC); + $arrayTagsXBeers = $stmt->fetchAll(); + } catch (PDOException $e) { + echo "Error in Beers: " . $e->getMessage(); + } + print_r($arrayTagsXBeers); + return $arrayTagsXBeers; +} diff --git a/search.php b/search.php index 3e0b0e0..11ea4f8 100644 --- a/search.php +++ b/search.php @@ -1,5 +1,94 @@ "; + +if($_GET["type"]=="tag"){ + $array=listBeersByTag($pdo, $tag); +} +if($_GET["type"]=="beer"){ + $name=$_GET["keyword"]; + $array=listBeersByName($pdo, $name); + foreach($arrayOfBeers as $row): + echo " +
+ +
"; + endforeach; +} +if($_GET["type"]=="brewery"){ + $name=$_GET["keyword"]; + $array=listBreweryByName($pdo, $name); + +} +if($_GET["type"]=="article"){ + $name=$_GET["keyword"]; + $array=listArticleByName($pdo, $name); + foreach($array as $row) : + echo "
"; + echo "
"; + endforeach; +} +if($_GET["type"]=="all"){ + $name=$_GET["keyword"]; + $array=listArticleByName($pdo, $name); + foreach($arrayOfBeers as $row): + foreach($array as $row) : + echo "
"; + echo "
"; + endforeach; + + $array=listBreweryByName($pdo, $name); + + $array=listBeersByName($pdo, $name); + + $array=listBeersByTag($pdo, $tag); +} + + +echo ""; +include("view/footer.php"); +//header("location: index.php"); \ No newline at end of file diff --git a/view/sidebar.php b/view/sidebar.php index ed99251..350c8f4 100755 --- a/view/sidebar.php +++ b/view/sidebar.php @@ -7,10 +7,10 @@ require_once("controller/listLatest.php");