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

I have a question about the teachers notes.

It says that we are supposed to replace the function get_item_id with the code

<? php
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;

What I want to know is where in the project are we supposed to do that.

edited code for formatting

As stated in the video, I think around 1:45, the teacher create a functions.php file. I would go back and watch the video starting around that point or from the beginning.

1 Answer

Sergey Podgornyy
Sergey Podgornyy
20,660 Points

Aaron, you could replace your code in index.html, for example, using function get_item_html. It will be much clear:

$pageTitle = "Personal Media Library";
$section = null;
include("inc/header.php"); ?>
        <div class="section catalog random">

            <div class="wrapper">

                <h2>May we suggest something?</h2>

                <ul class="catalog">
                        $random = array_rand($catalog,4);
                        foreach($random as $id){
                            echo get_item_html($id,$catalog[$id]);



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

If you are intresting, you can see, how I realized this project here.