Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

How can I add a link to the details page?

I created the table of item details and I want to know how to link to the page by clicking "View Details" in this page. http://testsite.gangstacat.com/catalog.php?cat=wanted

here is the code of functions.php

function get_item_html($id, $item){
    $output="<li><a href=''><img src='".$item["img"] ."' alt='".$item["title"]."'/>".$id."<p>View Details</p>" . "</a></li>";
    return $output;

function array_category($catalog, $category){

    foreach($catalog as $id=>$item){
        if($category==null OR strtolower($category)==strtolower($item["category"])){
            $sort=ltrim($sort, "The ");
            $sort=ltrim($sort, "A ");
            $sort=ltrim($sort, "An ");
    return array_keys($output);

Please edit this and see what i did to achieve the code formating. - KP

I guess I should add some code in <a href''> the URL would be something like details.php?id=<?php echo $id;?>

Konrad Pilch
Konrad Pilch
2,435 Points

I'm not sure, but each page should have its unique ID so you can select just the specific one. The code you posted echo $id, it seem it could work, or at least, it shoudl be like that i guess, but i don't know 100%. Each page has it's own ID for sure.

I tried the code but it didn't work.

2 Answers

Thanks :)

René Sánchez
René Sánchez
9,954 Points

Hey, at the end of the video it said to look at the teachers notes for adding exactly that link that you are looking for!

Simply add this to replace the get_item_html function:

function get_item_html($id,$item) { $output = "<li><a href='details.php?id=" . $id . "'><img src='" . $item["img"] . "' alt='" . $item["title"] . "' />" . "<p>View Details</p>" . "</a></li>"; return $output; }

René Sánchez
René Sánchez
9,954 Points

you have to do that in your functions.php file

sorry for the mess of code i copied and pasted :P...i recommend grabbing it directly from the teachers notes