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 trialQasim Hafeez
12,731 PointsQuestion about media_id
When I added "media_id" to the query like she does in the video, I got an error saying the 'media_id' was ambiguous. I changed it to "Media.media_id" and it worked. I thought I would have to add "Media.media_id" to the get_item_html function but that threw an error also. When I changed it back to "media_id" it worked. Does anyone know why this is?
1 Answer
Dennis Amiel Domingo
17,813 PointsYou might have added the "media_id" column in the "single_item_array" function. It should be added in the "full_catalog_array" function in the function.php file.
Add here:
function full_catalog_array(){
include("connection.php");
try {
$results = $db->query("SELECT media_id, title, category, img FROM media");
//echo "Retrieved Results";
} catch (Exception $e) {
echo "Unable to retrieve results";
exit;
}
$catalog = $results->fetchAll(PDO::FETCH_ASSOC);
return $catalog;
}
Note here:
function single_item_array($id){
include("connection.php");
try {
$results = $db->query(
"SELECT title, category, img, format, year, genre, publisher, isbn
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 = $id"
);
} catch (Exception $e) {
echo "Unable to retrieve results\n";
echo $e;
exit;
}
$catalog = $results->fetch(PDO::FETCH_ASSOC);
return $catalog;
}
Note: Sorry if my query is a little different than the one in the videos. I created my own database at home that's slightly different from this one.