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 trial

PHP Build a Basic PHP Website (2018) Listing and Sorting Inventory Items Displaying All Items

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Help! 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.

it 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

1 Answer

Can 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
Jonathan Grieve
Treehouse Moderator 91,253 Points

The 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 :)