PHP Build a Basic PHP Website Listing and Sorting Inventory Items Creating the Display Function

John Vicencio
John Vicencio
6,315 Points

Nothing is displaying for full catalog?

On https://teamtreehouse.com/library/build-a-basic-php-website/listing-and-sorting-inventory-items/creating-the-display-function where the functions.php is separated.

//functions.php in inc folder

function get_item_html($id, $item) {
  $output = "<li><a href='#'><img src='"
          . $item["img"] ."' alt='"
          . $item["title"] ."'>"
          . "<p>View Details</p>" 
          ."</a></li>";
  return;
}

Then on catalog.php shows a foreach loop calling the function with parameters.

//top section of the HTML document
include("inc/data.php");
include("inc/functions.php");
.
.
.
<div class="section catalog page">
  <div class="wrapper">
    <h1><?php echo $pageTitle; ?></h1>
    <ul class="items">
      <?php 
      foreach ($catalog as $id => $item) {
        echo get_item_html($id,$item);
      }
      ?>
    </ul>
  </div>
</div>

Then replacing the index.php unordered list elements using the above loop

// the same as in catalog.php
      foreach ($catalog as $id => $item) {
        echo get_item_html($id,$item);
      }
      ?>

The output shows "blank".

If I "echo" on catalog.com, I see the full catalog. But when I created a function just like what is shown on the video instruction, I'm seeing blank on the browser.

//original catalog.php unodered list items

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

Any ideas?

2 Answers

Hazem mosaad
Hazem mosaad
15,378 Points

HI John where is the return of the function Without the return the function not do anything !

function get_item_html($id, $item) {
  $output = "<li><a href='#'><img src='"
          . $item["img"] ."' alt='"
          . $item["title"] ."'>"
          . "<p>View Details</p>" 
          ."</a></li>";
  return $output;
}
John Vicencio
John Vicencio
6,315 Points

Thanks! I felt dumb.

Hazem mosaad
Hazem mosaad
15,378 Points

No No You Must write it in a paper and do more Exercise Never Give Up Continue Learning ,,You Are Welcome