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 trialDhruv Kapoor
2,902 Pointsfunctions.php
<?php
function full_catalog_array(){
include("connection.php");
try {
$result=$db->query("SELECT media_id, title, category, img FROM Media");
//echo "Retrieved the results";
} catch (Exception $e) {
echo "Bad query";
}
$catalog=$result->fetchAll();
return $catalog;
}
function single_item_array($id){
include("connection.php");
try {
$result=$db->prepare("
SELECT Media.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 = ?
");
$result->bindParam(1,$id,PDO::PARAM_INT);
$result->execute();
} catch (Exception $e) {
echo "Bad query";
exit;
}
$item=$result->fetch();//Since we want to take only one item
if(empty($item)) return $item;
try {
$result=$db->prepare("
SELECT fullname, role
FROM Media_People
JOIN People on Media_People.people_id=People.people_id
WHERE Media_People.media_id = ?
");
$result->bindParam(1,$id,PDO::PARAM_INT);
$result->execute();
} catch (Exception $e) {
echo "Bad query";
exit;
}
while($row=$result->fetch(PDO:FETCH_ASSOC)){
$item[$row["role"]][]=$row["fullname"];
}
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;
}
}
asort($output);
return array_keys($output);
}```
2 Answers
Dhruv Kapoor
2,902 PointsI think something is wrong with the query
Eric Schroeder
19,894 PointsYou can try var_dump($e) right after your error statement. That may give you more information.
Dhruv Kapoor
2,902 PointsDhruv Kapoor
2,902 Pointsdetails.php