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 Associative Arrays

Aananya Vyas
Aananya Vyas
20,157 Points

Oops! It looks like Task 1 is no longer passing.

The static HTML below displays information about one really great movie. In this code challenge, we'll modify this so that it instead displays information about an even better movie. We'll also modify it to use an associative array in PHP instead of static pieces of text. First, add a PHP code block above the HTML that creates an empty PHP array named $movie. the error says task one is not passing i have tried everything and cant understand where it went wrong!

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

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

3 Answers

Matti Mänty
Matti Mänty
5,885 Points

I ended up doing the code challenge from the top, to better see what's required by the Treehouse challenge.

I simplified the way we add the variables to the array and echoed the variables where the assignment asked to. Compare your code to mine and see where there might be extra brackets or missing brackets, semicolons or such. You might have accidentally pasted over some existing code and a closing </td> could be missing.

<?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>
Aananya Vyas
Aananya Vyas
20,157 Points

This was the only task getting in the way of completing the course ! Thanks alot!!

Matti Mänty
Matti Mänty
5,885 Points

Hmm, well first of all, I think the year, imdb ranking and imdb rating shouldn't be strings, but the real issue here might be the weird parentheses and closing and opening php tags I see all around the place.

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

Here there is an orphan angle bracket right after you start your php code. Also there is a parenthesis before the second php code. Also on the final row, there is a opening php tag, but the end tag is missing a question mark. Easier way to do this would be to combine those two echos anyways, like:

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

Later on you have an extra parenthesis also in the code, here.

 echo ($movie['director'] </td>

With these it should pass, unless I'm still missing something. Change the strings to numbers, too, while you're at it. Hope this helps!

Okay edit time: After your title and year echo, you begin a php tag, that disables the rest of the HTML until the very end. Instead every time you echo something, open and close php tags there. You seem to also be missing a semicolon after echoing the director.

Aananya Vyas
Aananya Vyas
20,157 Points
<?php 
$movie=array();
$movie['title']="The Empire Strikes Back";
$movie['year']="1980";
$movie['director']="Irvin Kershner";
$movie['imdb_rating']="8.8";
$movie['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>
Aananya Vyas
Aananya Vyas
20,157 Points

this still is not working...

Aananya Vyas
Aananya Vyas
20,157 Points

Bummer! We don't see the value of $movie["director"] within a <td> element.

this is the error^