Skip navigation
SeanWHall
Currently Being Moderated

PHP Code, Variables & CSS. Would this work?

Jun 16, 2012 8:39 AM

Hello,

I am new to PHP, this is my first script I have made without any help, I am using xammp to test my site, but the basics of the code is this. I am adding an include code into the navigation menu and in the CSS I have defined certain rules for the nav. Now in the code when you click on one of the links, it will change the variable to a corresponding number. The Code is pretty much self explanatory.

 

Menu.php:

<?
$active = 1;
?>    
    <ul>
      <li><a href="#"  onclick="<? $active = 1; ?>" class="<? if ($active = 1){?>#navigation ul li a.active<? } ?>">Portfolio</a></li>
      <li><a href="#"  onclick="<? $active = 2; ?>" class="<? if ($active = 2){?>#navigation ul li a.active<? } ?>">Web Examples</a></li>
      <li><a href="#"  onclick="<? $active = 3; ?>" class="<? if ($active = 3){?>#navigation ul li a.active<? } ?>">Contact Me</a></li>
    </ul>

Menu CSS:

 

#navigation { text-align: right; font-weight: bold; text-transform: uppercase; font-size:14px; line-height:18px; height:70px;}
#navigation ul{ list-style-type: none; }
#navigation ul li{ display:inline; padding-left:15px; }
#navigation ul li a{ text-decoration: none; color:#fff; }
#navigation ul li a:hover,
#navigation ul li a.active { color:#ffe6a5; }

 

Now what I want to happen is when you click on one of the links, it will change to active, changing the color of the text to tell the visitor that, that link is active. Now normally I would do it though CSS, changing the texts rule to the active, but in order to be able to change buttons without having to do it though all the pages and also because I want to start using PHP more.


The Include works, as you can see below, but the code above does not work, because the home button should be a light yellow color.

 

http://new.tinygrab.com/ed26669b22595f8ba22993f2e4ac0d6ebac59886ea.png

 
Replies

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points