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

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,942 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,942 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