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 Displaying All Items

suyash patankar
suyash patankar
2,310 Points

Syntax error - books list not displayed

The code as shown in video

  <ul class="items">
        <?php  
foreach($catalog as $item){
      echo "<li><a href='#'><img src='"
        . $item["img"] . "' alt='"
        . item["title"] . "'  />"
        . "<p>View details</p>" 
        . "</a></li>";
    }
        ?>
      </ul>

is giving a syntax error Parse error: syntax error, unexpected '[', expecting ',' or ';' in /home/treehouse/workspace/catalog.php on line 40

line 40 is . item["title"] . "' />"

suyash patankar
suyash patankar
2,310 Points

code is not displayed properly here, but please help with foreach loop part

edited for syntax highlighting. :)

4 Answers

Sadly no -- my first (uninformed) thought is that you're missing the '$' on the second item['title'], but I really don't know enough PHP to have anything constructive to say. :)

suyash patankar
suyash patankar
2,310 Points

Thank you @Cena Mayo

any solution for error removal?

suyash patankar
suyash patankar
2,310 Points

yes, I think that is the issue, thank you so much, I am also new to php

suyash patankar
suyash patankar
2,310 Points

It worked, you can close this discussion, thank you very much for your help @Cena Mayo