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 trialJonathan Grieve
Treehouse Moderator 91,253 PointsHelp! Where are the images?
They're not picking up from the data file, which is successfully linked.
This is my code.
A portion of my data,php file.
<?php
$catalog[101] = [
"title" => "A Design Patterns: Elements of Reusable Object-Oriented Software",
"img" => 'img/media/design_patterns.jpg',
"genre" => "Tech",
"format" => "Paperback",
"year" => 1994,
"category" => "Books",
"authors" => [
"Erich Gamma",
"Richard Helm",
"Ralph Johnson",
"John Vlissides"
],
"publisher" => "Prentice Hall",
"isbn" => '978-0201633610'
];
<ul class = "items">
<?php
foreach($catalog as $item) {
echo "<li><a href='#'><img src'"
. $item["img"] . "' alt='"
. $item["title"] . "' />"
. "<p>View Details</p>"
. "</a></li>";
}
?>
</ul>
The files are in the right place... the includes link correctly, I've tried tinkering with the file extension... they're just not showing up on localhost.
1 Answer
thomascawthorn
22,986 PointsCan you inspect the element and paste in the image source?
It looks like your html is invalid - you need an '=' after src:
<img src="/some-source">
Right now you're printing
<img src"/some-source">
Also, why use single quotes in your html? I would flip the php string to use single quotes and html to use double quotes :-)
Jonathan Grieve
Treehouse Moderator 91,253 PointsThe quote stuff is just something I tried to get the images to appear. But the dodgy source attribute is something I simply didn't see. That's bound to be it, thanks :)
calvindiguidig
Courses Plus Student 4,388 Pointscalvindiguidig
Courses Plus Student 4,388 Pointsit is working on workspace? then if the image is not showing properly usually it's about the permission or owner group try to check permission on your image folder and image itself