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

Flo Tubes
Flo Tubes
5,110 Points

Displays too many items

I the video it displays 4 items horizontally. On my screen displays way more items verticaly.

This is my catalog.php:

<?php 
include("include/data.php");






$pageTitle = "Full Catalog";
$section = null;

if(isset($_GET["cat"])){

  if($_GET["cat"]== "books"){
      $pageTitle = "Books";
    $section = "books";
  }
     else if($_GET["cat"]== "movies"){
       $pageTitle = "Movies";
       $section = "movies";
  }
    else if($_GET["cat"] == "music"){
      $pageTitle= "Music";
      $section = "music";
  }
}
include("include/header.php");

?>

<div class="section catalog page">
  <div class="wrapper">

      <h1><?php echo $pageTitle;?></h1>

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

  </div>




</div>
<?php include("include/footer.php");?>

2 Answers

Seth Kroger
MOD
Seth Kroger
Treehouse Moderator 56,267 Points

[edited OP for formatting -- to include a code block you should rap your code with 3 backticks (```) on the line before and after as shown in the Markdown cheatsheet.]

In this line you have a semi-colon in the middle of the output you are trying to build. This will end the echo statement and cut off anything after it. This includes the closure of the image tag and closing tags of the anchors and list items.

          .$item["title"];"'/>"
Flo Tubes
Flo Tubes
5,110 Points

It displays them properly now but still too many but I think I can fix that somehow

Prince Henry
Prince Henry
4,312 Points

perhaps you should look into your <ul> class and try using <ul class="items">