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

How is the <a href="#"> getting a source code from the php foreach loop in this video?

Here is the foreach loop Alena uses in this video

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

When I view the source code, I can see how it generated the img src and the source for the alt code from the array, but how does php generate the "a href source code when in the video we onlly used a "#" for the source code of it it generated this code <a href="details.php?id=201">?

<ul class="items">
    <li><a href="details.php?id=201"><img src="img/media/forest_gump.jpg" alt="Forrest 
         Gump"> <p>View Details</p></a></li>

      <li><a href="details.php?id=204"><img src="img/media/princess_bride.jpg" alt="The 
        Princess Bride"><p>View Details</p></a></li>

      <li><a href="details.php?id=302"><img src="img/media/elvis_presley.jpg" alt="Elvis 
       Forever"><p>View Details</p></a></li>

      <li><a href="details.php?id=303"><img src="img/media/garth_brooks.jpg" alt="No 
       Fences"><p>View Details</p></a></li>                             
</ul>

1 Answer

Stefan Göppert
Stefan Göppert
1,735 Points

You're in the wrong file. The loop is within the catalog.php, you're looking at the index.php site. You need to click one of the categories at the top, "Books", "Movies" or "Music" to see the output of the catalog.php file.