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

Joy Manuel
Joy Manuel
6,449 Points

Displaying Item Details showing up at the bottom of the book and no Notice warning.

Details are at the bottom of the book are not on the right side as the video. Also, I don't see output Notice under Authors. It will only display the word Array.

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

if (isset($_GET["id"])) {
    $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 class="section page">

    <div class="wrapper">

        <div class="media-picture">

        <span>
            <img src="<?php echo $item["img"]; ?>" alt="<?php echo $item["title"]; ?>" />
        </span>

        <div class="media-details">

            <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>Authors</th>
                    <td><?php echo $item["authors"]; ?></td>
                </tr>
                <tr>
                    <th>Publisher</th>
                    <td><?php echo $item["publisher"]; ?></td>
                </tr>
                <tr>
                    <th>ISBN</th>
                    <td><?php echo $item["isbn"]; ?></td>
                </tr>
                <?php } ?>
            </table>

 </div>

Moderator edited: Markdown added so that code renders properly in the forums.

1 Answer

Jennifer Nordell
STAFF
Jennifer Nordell
Treehouse Staff

Hi there, Joy Manuel ! Looks like you're doing terrific from where I'm sitting! I found the two things that are causing this behavior.

On or around line 15, you have a <div> with the class "media-picture" which contains a span which itself contains an image. There was supposed to be a closing </div> tag there which was inadvertently omitted. This is what is causing the strange CSS behavior you're seeing.

So where you have:

 <div class="media-picture">

        <span>
            <img src="<?php echo $item["img"]; ?>" alt="<?php echo $item["title"]; ?>" />
        </span>

I would expect to see:

 <div class="media-picture">

        <span>
            <img src="<?php echo $item["img"]; ?>" alt="<?php echo $item["title"]; ?>" />
        </span>
</div>  // note the ending div here

As for your Authors showing up as "Array" instead of the list of authors, we need to implode that array so that it will list out the contents correctly.

You have:

<td><?php echo $item["authors"]; ?></td>

But that should be:

 <td><?php echo implode(", ",$item["authors"]); ?></td>

Hope this helps! :sparkles:

Joy Manuel
Joy Manuel
6,449 Points

Thanks for looking into it. I figured it out, but couldn't find my question again, to re-post an update. I posted my code as I was in the middle of the video. I appreciate your help, Jennifer :).