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

cant get past this challenge.. need help.. it says theres something wrong with the HTML..

Challenge task 7 of 7 Right now, the three <td> elements have information about the original movie as static pieces of text. Replace each of those with PHP commands that INSTEAD display information about the new movie from the array instead. (Be sure to leave the <td> tags intact.)

<?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"] ?> (1980)</h1> <h1><?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>

8 Answers

hmmm i copied your code and i get this error: The name of the director is displayed in the browser, but the HTML around it does not seem to be correct. Please double-check the spacing and other formatting.

i double-checked but it's still the same.. hmmm

that's okay...it's the answer to number 3 question. and if i delete that it will create an error that says it doesn't answer number 3 anymore. :) thanks.. this is the one that's been causing trouble :

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

Gregory Serfaty
Gregory Serfaty
37,140 Points

Your code is ok it is very weird . do you try to delete the quote in your array like this "imdb_ranking" => 11

no, can't..it would create an error. im assigning a value to that array variable. :) it's the code from the test challenge so yeah, it's a bit weird.. :)

Gregory Serfaty
Gregory Serfaty
37,140 Points

I do this and i have a success

<?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>

challenge 1 to 7, the goal is to teach how to avoid hard coded data and use PHP to change the state of data according to the web page or situation

<?php $movie = ["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>

Gregory Serfaty
Gregory Serfaty
37,140 Points

Why you let the year (1980) <?php echo $movie["title"] ?> (1980) <?php echo "(" . $movie["year"] . ")" ?> Do you try without?

You can do like this <h1><?php echo $movie['title'] ?> (<?php echo $movie['year'] ?>)</h1>