PHP/HTML help

Discussion in 'Web Design and Development' started by Anteeks, Mar 25, 2014.

  1. Anteeks macrumors newbie

    Joined:
    Feb 23, 2012
    Location:
    Sweden
    #1
    Code:
    
    
    So, I'm trying to make a webpage using HTML/CSS and PHP. I divided the project in separate files (one for header, footer, every subpages etc.).

    What I want to do is to highlight the current meny choice. I do this by defining a ID per page, and use this ID to access some CSS code.

    I define a variable $pageId, that writes out in header.php to get a dynamic ID per page (which I also did with the webpage title).

    But the problem is - it doesn't work and I get an annoying "id='me' > " printed out on the left upper screen. The closest I have got to is to hard-code it (which I don't want to) by writing "<body id='pagename' >" which makes the highlightning work, but it still prints out the text on top.

    Here is the code for the subpage:

    Code:
    
    <?php 
    include("incl/config.php");
    $pageTitle = "titlename";
    $pageId = "me";
    
    
    $pageStyle = '
    figure { 
     -webkit-border-radius: 10px;
     -moz-border-radius: 10px;
     border-radius: 10px;
    
     border-color:#5C0A0A;
    
     -moz-box-shadow: 10px 10px 5px #8A0F0F;
     -webkit-box-shadow: 10px 10px 5px #8A0F0F;
     box-shadow: 10px 10px 5px #8A0F0F;
    }
    ';
    
    ?>
    
    <?php include("incl/header.php"); ?>
    
    
    
    
    Code in header.php (where I want to write out the ID).

    Code:
    <head>
    
      <title><?php echo $pageTitle; ?></title>
      <?php if(isset($pageStyle)) : ?>
     <style type="text/css">
       <?php echo $pageStyle; ?>
     </style>
     <?php endif; ?> 		
    
    	
    </head>
    <body><?php if(isset($pageId)) echo " id='$pageId' "; ?>>
    
    <!-- Header -->
    <header id="above">
     <nav class="related">
     </nav>
    </header>
    
    
    
    
    <header id="top">
     
    
     <nav class="navmenu">
      <a id="me-"     href="me.php">Me</a>
     </nav>
    
      </header>
    
    And the code in CSS to highlight the meny choice (when body#id and a#id is equal)

    Code:
     body#me a#me-,
    {background:#858585;border:2px solid #656565;} 
    
    Anyone knows whats wrong with the code?
     
  2. Darth.Titan macrumors 68030

    Darth.Titan

    Joined:
    Oct 31, 2007
    Location:
    Austin, TX
    #2
    It's right there in your header.php file:
    PHP:
    </head>
    <body><?php if(isset($pageId)) echo " id='$pageId' "?>>
    should be
    PHP:
    </head>
    <body<?php if(isset($pageId)) echo " id='$pageId' "?>>
    Note you put a closing > on your body tag before echoing the id. That's why you were seeing "id='me' > " printed out at the top of each page.
     
  3. 960design macrumors 68020

    Joined:
    Apr 17, 2012
    Location:
    Destin, FL
    #3
    I hate it when I do stuff like that.
    Three hours on Friday looking for a bug that ended up being =! instead of !=

    This silly things we do... my mistakes could have their own web blog
     
  4. Darth.Titan macrumors 68030

    Darth.Titan

    Joined:
    Oct 31, 2007
    Location:
    Austin, TX
    #4
    Yep, just remember it happens to the best of us.
     

Share This Page