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

coskun olcucu
coskun olcucu
5,340 Points

I have issue when i hit the category link.

Hello, I have an issue on breadcrumbs. when I hit the category on the link let's say "music" category. My browser link ends cat=%20music

Where does %20 comes from? How to get rid of %20 from the link.

Hi coskun,

%20 is the url encoding for the space character. So your code is likely inserting a space.

If you can post the code that pertains to this issue, then we can try to help you figure out what the issue might be.

3 Answers

coskun olcucu
coskun olcucu
5,340 Points

here is the code,

<?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="breadcrumbs">
               <a href="catalog.php">Full Catalog</a>
                &gt; <a href="catalog.php?cat= <?php echo strtolower($item["category"]); ?>" >
                     <?php echo $item["category"] ?> </a>
                &gt; <?php echo $item["title"]; ?> 

            </div>
        <div class="media-picture">

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

        </div>

        <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 implode(", ",$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 } else if (strtolower($item["category"]) == "movies") { ?>
                <tr>
                    <th>Director</th>
                    <td><?php echo $item["director"]; ?></td>
                </tr>
                <tr>
                    <th>Writers</th>
                    <td><?php echo implode(", ",$item["writers"]); ?></td>
                </tr>
                <tr>
                    <th>Stars</th>
                    <td><?php echo implode(", ",$item["stars"]); ?></td>
                </tr>
                <?php } else if (strtolower($item["category"]) == "music") { ?>
                <tr>
                    <th>Artist</th>
                    <td><?php echo $item["artist"]; ?></td>
                </tr>
                <?php } ?>
            </table>

        </div>

    </div>

</div>

I did not test out your code but I think your problem is in this line:

&gt; <a href="catalog.php?cat= <?php echo strtolower($item["category"]); ?>" >

Notice that you have a space right after the = sign but before you echo the category. I think that is what is putting the space in the link and then the browser is url encoding that space to %20 when it displays it in the address bar.

Let me know if that doesn't resolve your issue.

coskun olcucu
coskun olcucu
5,340 Points

Hi Jason Anello, I took your advice and problem has gone.Thank you for your help.