Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Build a Basic PHP Website (2018) Listing and Sorting Inventory Items Associative Arrays

Associative arrays challenge task 7 of 7 -- can't complete challenge, correct code is not detected.

Check work doesn't see <?php echo $movie['director'] ?> within the td element. Code as follows:

<?php

$movie = array( 'title' => 'The Empire Strikes Back', 'year' => 1980, 'director' => "Irvin Kershner", 'imdb_rating' => 8.8, 'imdb_ranking' => 11 ); ?>

<h1><?php echo $movie['title'] . $movie['year']?></h1>

<table> <tr> <th>Director</th> <td><?php echo $movie['director'] ?> </td> </tr> <tr> <th>IMDB Rating</th> <td><?php echo $movie['imdb_rating'] ?></td> </tr> <tr> <th>IMDB Ranking</th> <td><?php echo $movie['imdb_ranking'] ?></td> </tr> </table>

5 Answers

William, here's the whole thing:

<?php
$movie = array( 
    'title' => 'The Empire Strikes Back', 
    'year' => 1980, 
    'director' => "Irvin Kershner", 
    'imdb_rating' => 8.8, 
    'imdb_ranking' => 11 
); 
?>
<h1><?php echo $movie["title"]; ?> <?php echo $movie["year"]; ?></h1>

<table>
  <tr>
    <th>Director</th>
    <td><?php echo $movie["director"]; ?></td>
  </tr>
  <tr>
    <th>IMDB Rating</th>
    <td><?php echo $movie["imdb_rating"]; ?></td>
  </tr>
  <tr>
    <th>IMDB Ranking</th>
    <td><?php echo $movie["imdb_ranking"]; ?></td>
  </tr>
</table>

William, two problems. First, this line:

<h1><?php echo $movie['title'] . echo $movie['year']?></h1>

needs to look like this:

<h1><?php echo $movie["title"]; ?> <?php echo $movie["year"]; ?></h1>

I.e., the editor asked for two php statements. And this line:

    <td><?php echo $movie['director'] ?> </td>

needs to look like this:

    <td><?php echo $movie["director"]; ?></td>

Note that the editor doesn't like the missing semi-colon.

Thanks for your help, unfortunately after the above changes, I'm still getting the same message. Tried in both Firefox and Chrome.

Not sure if it was fixed or what - but after pasting in the code from above it let me complete the challenge. I'm comparing what I had before with the above code and I can't find any difference so who knows. Thanks much for your help sir.

osvaldo gonzalez
osvaldo gonzalez
2,167 Points

<?php $movie = array ( 'title' => 'The Empire Strikes Back', 'year' => '1980', 'director' => 'Irvin Kershner', 'imdb_rating' => 8.8 , 'imdb_ranking' => 11); ?>

<h1><?php echo $movie['title']; ?>(<?php echo $movie['year']; ?>) </h1>

<table> <tr> <th>Director</th> <td><?php echo $movie['director'] ?></td> </tr> <tr> <th>IMDB Rating</th> <td><?php echo $movie['imdb_rating'] ?></td> </tr> <tr> <th>IMDB Ranking</th> <td><?php echo $movie['imdb_ranking'] ?></td> </tr> </table>