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

Gremyko Coleman
Gremyko Coleman
6,273 Points

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