Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Integrating PHP with Databases!
You have completed Integrating PHP with Databases!
Preview
Our details page is lacking any people associated to the particular item: such as Authors or Directors. We want to pull all the people, with their roles, and add them to our catalog in a multidimensional associative array.
Example Code
try {
$result = $db->prepare("
SELECT fullname,role
FROM Media_People
JOIN People ON Media_People.people_id=People.people_id
WHERE media_id = ?");
$result->bindParam(1,$id,PDO::PARAM_INT);
$result->execute();
} catch (Exception $e) {
echo "bad query";
echo $e;
}
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
Our single_item_array function
has one query right now
0:00
that retrieves data from the Media table,
Genre table and
0:01
optionally from the Books table,
but only if that data exists.
0:05
Let's add another query that will retrieve
the people associated with this item.
0:10
We'll need to add the people with
their roles to our item array,
0:15
in the same format that
they were in before.
0:18
Let's take a look at our data.php
file to review what the item array
0:22
used to look like.
0:26
Inside each item we had an array element
for each role, using the role as the key.
0:27
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up