Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Vladislav Mavrin
PRO
Vladislav Mavrin
Pro Student 3,125 Points

Clicking "View details" leads to catalog.php

I have changed get_item_html function according to the teacher's notes, but everytime I click View Details it brings me back to catalog.php without displaying any item details...

Would appreciate your help. Thanx!

details.php

<?php 

include("inc/data.php");
include("inc/functions.php");




if (isset($_GET["is"])) {
    $id = $_GET["id"];
    if (isset($catalog[$id])) {
        $item = $catalog[$id];
    }
} 

if (!isset($item)) {
    header("location:catalog.php");
    exit;
}


$pageTitle = $item['title'];
$section = null;
include ("inc/header.php"); ?>

<div calss="section page">
    <div class="wrapper">
        <div class="media-picture">
            <span>
<img src="<?php echo $item["img"]; ?>" alt="<?php echo $item["title"]; ?>"/>
</span>
</div>
<div class="meadia-details"></div>
<h1><?php echo $item["title"]; ?></h1>
<table>
    <tr>
        <th>Category</th>
        <td><?php echo $item["category"]; ?></td>
    </tr>
    <tr>
        <th>Genre</th>
        <td><?php echo $item["genre"]; ?></td>
    </tr>
    <tr>
        <th>Format</th>
        <td><?php echo $item["format"]; ?></td>
    </tr>
    <tr>
        <th>Year</th>
        <td><?php echo $item["year"]; ?></td>
    </tr>
    <?php 
    if (strtolower($item["category"]) == "books") {
        ?>
    <tr>
        <th>Category</th>
        <td><?php echo $item["authors"]; ?></td>
    </tr>
    <tr>
        <th>Category</th>
        <td><?php echo $item["publisher"]; ?></td>
    </tr>
    <tr>
        <th>Category</th>
        <td><?php echo $item["isbn"]; ?></td>
    </tr>
    <?php }
    ?>
</table>


    </div>
</div>

catalog.php

<?php 

include("inc/data.php");
include("inc/functions.php");

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



if (isset($_GET["cat"])) {
if ($_GET["cat"] == "books") {
    $pageTitle = "Books";
    $section = "books";
} else if ($_GET["cat"] == "movies") {
    $pageTitle = "Movies";
    $section = "movies";
} else if ($_GET["cat"] == "music") {
    $pageTitle = "Music";
    $section = "music";
}
} 
include ("inc/header.php"); ?>

<div class="section catalog page">
    <div class ="wrapper">

    <h1><?php 
    if ($section != null) {
        echo "<a href='catalog.php'>Full Catalog</a> &gt; ";
    }
    echo $pageTitle; ?></h1>

    <ul class="items">
        <?php 
        $categories = array_category($catalog,$section);
                        foreach ($categories as $id) {
                        echo get_item_html($id,$catalog[$id]);
        }
        ?>
    </ul>


    </div>
</div>
<?php include ("inc/footer.php"); ?>

1 Answer

Vladislav Mavrin
PRO
Vladislav Mavrin
Pro Student 3,125 Points

A misprint in if statement

if (isset($_GET["id"])) {
    $id = $_GET["id"];
    if (isset($catalog[$id])) {
        $item = $catalog[$id];
    }
} 

had iS instead of id