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

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 82,379 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

Tom Cawthorn
Tom Cawthorn
22,981 Points

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 82,379 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 :)