PHP Build a Basic PHP Website (2018) Building a Media Library in PHP Including the Header

mohammed mayat
mohammed mayat
4,228 Points

page not displaying properly

i had to comment out header and nav to get the page looking the same, has anyone else had this problem https://w.trhou.se/5ol77rktex

1 Answer

Dan Weru
Dan Weru
47,637 Points

Hey, you just need to tweak you code a little. The purpose of including the header.php file in the index.php and suggest.php is so that you can avoid repeating code.

In other words the code inside the header.php should not be repeated in the index.php nor in the suggest.php. Therefore your index.php should look like

<?php include("inc/header.php"); ?> <!-- this line pulls in the code from header.php -->

    <div class="section catalog random">
      <div class="wrapper">
          <h2>May we suggest something?</h2>
          <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>
        </div>
      </div>
    </div>
    <div class="footer"><!--end content-->
      <div class="wrapper">
        <ul>        
          <li><a href="http://twitter.com/treehouse">Twitter</a></li>
          <li><a href="https://www.facebook.com/TeamTreehouse">Facebook</a></li>
        </ul>
        <p>&copy;2015 Personal Media Library</p>
      </div>
    </div>
  </body>
</html>