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 Simple PHP Application Listing Inventory Items Associative Arrays

Graham Patrick
Graham Patrick
8,294 Points

Stuck here with this one

ok adding an array for the film change quiz, my code looks like this

<?php $movie = array( "title" => "The Empire Strikes Back", ); ?> <h1><?php echo $movie["title"]; ?></h1>

Its telling me its not correct? Any ideas?

8 Answers

Graham Patrick
Graham Patrick
8,294 Points
<?php
$products = array();
$products[101] = array(
    "name" => "Logo Shirt, Red",
    "img" => "img/shirts/shirt-101.jpg",
    "price" => 18
);
$products[102] = array(
    "name" => "Mike the Frog Shirt, Black",
    "img" => "img/shirts/shirt-102.jpg",
    "price" => 20
);
$products[103] = array(
    "name" => "Mike the Frog Shirt, Blue",
    "img" => "img/shirts/shirt-103.jpg",
    "price" => 20
);
$products[104] = array(
    "name" => "Logo Shirt, Green",
    "img" => "img/shirts/shirt-104.jpg",
    "price" => 18
);
$products[105] = array(
    "name" => "Mike the Frog Shirt, Yellow",
    "img" => "img/shirts/shirt-105.jpg",
    "price" => 25
);
$products[106] = array(
    "name" => "Logo Shirt, Gray",
    "img" => "img/shirts/shirt-106.jpg",
    "price" => 20
);
$products[107] = array(
    "name" => "Logo Shirt, Turquoise",
    "img" => "img/shirts/shirt-107.jpg",
    "price" => 20
);
$products[108] = array(
    "name" => "Logo Shirt, Orange",
    "img" => "img/shirts/shirt-108.jpg",
    "price" => 25,
);
?>
<?php
$pageTitle = "Mike's Full Catalog of Shirts";
$section = "shirts";
include('inc/header.php');
?>

<div class="section page shirts">
    <div class="wrapper">
        <h1>Mike&rsquo;s Full Catalog Of Shirts</h1>
        <ul class="products">
            <?php foreach ($products as $product) { ?>
                <li><a href="#"
                       <img src="<?php echo $product["img"]; ?>" alt="<?php echo $product["name"]; ?>">
                        <p>View Details</p>
                    </a></li>
            <?php } ?>
        </ul>
    </div>
</div>
<?php include ('inc/footer.php'); ?>
            ```

Try to close the a tag :

<li><a href="#">

Hello,

You must not put a comma after the last element of the array.

<?php $movie = array( "title" => "The Empire Strikes Back"); ?> <?php echo $movie["title"]; ?>
Graham Patrick
Graham Patrick
8,294 Points

Thanks for that !! Maybe another question my browser is not displaying the product images

Code is:

<div class="section page shirts"> <div class="wrapper"> <h1>Mike’s Full Catalog Of Shirts</h1> <ul class="products"> <?php foreach ($products as $product) { ?> <li><a href="#" <img src="<?php echo $product["img"]; ?>" alt="<?php echo $product["name"]; ?>"> <p>View Details</p> </a></li> <?php } ?> </ul> </div> </div> <?php include ('inc/footer.php'); ?>

URL: http://www.morby-raybould.graphics/mikeshirts/shirts.php#

Cant get them to show, when i inspect element they are there if i click the link

Can you paste all the view code?

Graham Patrick
Graham Patrick
8,294 Points

mikeshirts --- css --- img -----shirts ---inc

thats the structure

Graham Patrick
Graham Patrick
8,294 Points

css folder , img, folder with sub folder for Shirts and an inc folder!

the whole folder titled mikeshirts is a sub folder in public_html

Graham Patrick
Graham Patrick
8,294 Points

So simple but couldnt see for looking!! Thanks so much!

You are welcome :)