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
Morrice Pfeiffer
4,162 PointsNow it hates my html??
Jeez what a struggle.Associative Arrays
Now it hates my html.
Thoughts please and thank you.
<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
Randy Hoyt
Treehouse Guest TeacherMorrice,
I apologize for the trouble! Look at the output in the browser on the right. The reason it is failing is because it is displaying the name of the movie and the year twice. You have a stray "The Empire Strikes Back1980" in between the H1 and the TABLE tags.
Overall, It looks like you missed the main goal of the challenge. Again, I apologize for all the trouble! Let me walk you through it. You should not be typing out the name "The Empire Strikes Back" in the HTML directly. You should be echoing out the value from the array. You should have created an array above the HTML and then used the echo command to display the name of the movie inside the H1. You should be echoing out the element from the array with PHP, not just re-typing the name of the movie again.
Step 3:
<?php
$movie["title"] = "The Empire Strikes Back";
?><h1><?php echo $movie["title"]; ?> (1985)</h1>
<table>
<tr>
<th>Director</th>
<td>Robert Zemeckis</td>
</tr>
<tr>
<th>IMDB Rating</th>
<td>8.5</td>
</tr>
<tr>
<th>IMDB Ranking</th>
<td>53</td>
</tr>
</table>
The next two steps ask you to add another element to the array and then replace another static piece of text with a PHP command, like this:
Step 5:
<?php
$movie["title"] = "The Empire Strikes Back";
$movie["year"] = 1980;
?><h1><?php echo $movie["title"]; ?> (<?php echo $movie["year"]; ?>)</h1>
<table>
<tr>
<th>Director</th>
<td>Robert Zemeckis</td>
</tr>
<tr>
<th>IMDB Rating</th>
<td>8.5</td>
</tr>
<tr>
<th>IMDB Ranking</th>
<td>53</td>
</tr>
</table>
I think after that you figured it out. Your code for Steps 6 and 7 looks good, adding the elements to the array and replacing the static pieces of text with those values.
Step 7:
<?php
$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>
Does that help?
Elliott Frazier
Courses Plus Student 9,647 Pointsit looks like all you need to do is bring your h1 tag down to be under your PHP commands.
Elliott Frazier
Courses Plus Student 9,647 PointsCould you please provide a link to the code challenge? The HTML looks fine.
Morrice Pfeiffer
4,162 Points <h1><?php echo $movie["title"]; ?>The Empire Strikes Back (1980)</h1>
<?php
$movie["title"] = "The Empire Strikes Back";
$movie["year"] = "1980";
$movie["director"] = "Irvin Kershner";
$movie["imdb_rating"] = 8.8;
$movie["imdb_ranking"] = 11;
echo $movie["title"];
echo $movie["year"];
?>
<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>
Heres what happened. The last line <td> had the number 53 in it. I originally entered a new line of code above that, that started with <th> instead of <td>. Pushed submit. Saw my formatting error and corrected it.
Then my error comes back as "Bummer! The HTML for this page is not quite right"
Thanks Elliot
Morrice Pfeiffer
4,162 PointsHi Randy
Thats not fair. You make it look easy...lol
Firstly don't apologize for the challenge. I have to stretch this old brain of mine and sometimes I get it and sometimes I don't. When I read your code I understand exactly whats going on and thats actually saying a lot considering 1 month ago it all look "Greek" to me.
You know what might help is an "exploded" view of an array with a definitions of what data populates what fields and why. Like a map. Have you ever seen anything like that? Does it even exist?
BTW sometimes when I don't get the code right I use a php tester. Often the tester will say pass but Treehouse says no, so I end up tweaking the code till it works.
Thanks again.
I am not giving up..
M