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


What did I do wrong? Site says "Unable to retrieve results".. Seems to skip the try..

// funtions.php <?php

function full_catalog_array() { include("connection.php");

try { $results = $db->query("SELECT media_id, title, category FROM Media"); } catch(Exception $e) { echo "Unable to retrieve results"; exit; }

$catalog = $results->fetchAll(); return $catalog; }

function single_item_array($id) { include("connection.php");

try { $results = $db->prepare(" SELECT title, category, format, year, genre, publisher, isbn FROM Media_People JOIN People ON Media_People.people_id = People.people_id WHERE Media_People.media_id = ?" ); $results->bindParam(1,$id,PDO::PARAM_INT); $results->execute();

} catch(Exception $e) { echo "Unable to retrieve results"; exit; } while ($row = $results->fetch(PDO::FETCH_ASSOC)) { $item[$row["role"]][] = $row["fullname"]; }

$item = $results->fetch(); if(empty($item)) return $item;

try { $results = $db->prepare(" SELECT full_name, role FROM Media JOIN Genres ON Media.genre_id = Genres.genre_id LEFT OUTER JOIN Books ON Media.media_id = Books.media_id WHERE Media.media_id = ?" ); $results->bindParam(1,$id,PDO::PARAM_INT); $results->execute();

} catch(Exception $e) { echo "Unable to retrieve results"; exit; }

return $item; }

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

function array_category($catalog,$category) { $output = array();

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

return array_keys($output);


// details.php <?php include("inc/functions.php"); //$catalog = full_catalog_array();

if (isset($_GET["id"])) { $id = filter_input(INPUT_GET,"id", FILTER_SANITIZE_NUMBER_INT); $item = single_item_array($id); }

if (empty($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 class="media-picture">

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


    <div class="media-details">

        <h1><?php echo $item["title"]; ?></h1>

                <td><?php echo $item["category"]; ?></td>
                <td><?php echo $item["genre"]; ?></td>
                <td><?php echo $item["format"]; ?></td>
                <td><?php echo $item["year"]; ?></td>
            <?php if (strtolower($item["category"]) == "books") { ?>
                <td><?php echo implode(", ",$item["author"]); ?></td>
                <td><?php echo $item["publisher"]; ?></td>
                <td><?php echo $item["isbn"]; ?></td>
            <?php } else if (strtolower($item["category"]) == "movies") { ?>
                <td><?php echo implode(", ",$item["director"]); ?></td>
                <td><?php echo implode(", ",$item["writer"]); ?></td>
                <td><?php echo implode(", ",$item["star"]); ?></td>
            <?php } else if (strtolower($item["category"]) == "music") { ?>
                <td><?php echo implode(", ",$item["artist"]); ?></td>
            <?php } ?>