PHP Build a Basic PHP Website (2018) Listing and Sorting Inventory Items Displaying All Items

Arturo Espinoza
Arturo Espinoza
9,180 Points

To many images in a catalog

When viewing a specific catalog (books for example) I am supposed to be shown only images pertaining to that category. But instead, all books, movies, and music appear. Can someone take a look at the code and see where I went wrong please.



$pageTitle = "Full Catalog";
$section = null;

if (isset($_GET["cat"])){
    if ($_GET["cat"] == "books") {
    $pageTitle = "Books";
    $section = "books";
    } else if ($_GET["cat"] == "movies") {
    $pageTitle = "Movies";
    $section = "moives";
    } else if ($_GET["cat"] == "music") {
    $pageTitle = "Music";
    $section = "music"; }

include("inc/header.php"); ?>

<div class="section catalog page">
    <div class="wrapper">
        <h1><?php echo $pageTitle; ?></h1>

        <ul class="items">
            foreach ($catalog as $item) {
                echo "<li><a href'#'><img src='" 
                    . $item["img"] . "' alt='"
                    . $item["title"] . "' />"
                    . "<p>View details</p>"
                    . "</a></li>";
<?php include("inc/footer.php"); ?>

1 Answer

Jose Vaca Cipres
Jose Vaca Cipres
10,724 Points

That is because you are displaying all the images whatever happens because you don't "receive" a $_GET and you don't evaluate (with IF Conditional) the category for Books, Movies and Music.