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

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.