PHP Build a Basic PHP Website Listing and Sorting Inventory Items Displaying All Items

suyash patankar
suyash patankar
2,309 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,309 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,309 Points

Thank you @Cena Mayo

any solution for error removal?

suyash patankar
suyash patankar
2,309 Points

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

suyash patankar
suyash patankar
2,309 Points

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