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 trialdannyavery
Courses Plus Student 801 PointsQuery not working with JOIN's. What am I missing?
function single_item_array($id) {
include("connection.php");
try {
$results = $db->query(
"SELECT media_id, 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"
);
// echo "Retrieved Results";
} catch (Exception $e) {
echo "Unable to Retrieve Results";
exit;
}
$catalog = $results->fetch();
return $catalog;
}
var_dump(single_item_array(1));
Ashish Mehra
Courses Plus Student 33 PointsAshish Mehra
Courses Plus Student 33 PointsHey Dannyavery, As you know you are using join here on books and genres table. Here in our database we have media_id in 2 tables i.e. media and books table so in query you must specify the table from which you are capturing media_id.If you are fetching it from media table then you have to write something like media.media_id & in case of books books.media_id.
But here you already getting media_id form url.So I don't think you need to select media_id.
I hope you understand