dennismonsewicz Posted February 2, 2009 Share Posted February 2, 2009 I have this if statement if($action == 'manage') { $active = 'class="active"'; } elseif($action == 'settings') { $active = 'class="active"'; } elseif($action == 'write') { $active = 'class="active"'; } else { $active = ''; } it is supposed to write the class to the link according to which action is in place... and its not working css <div class="navigation"> <ul> <li><a href="index.php?action=write" <?php echo $active; ?>>WRITE</a></li> <li><a href="index.php?action=manage" <?php echo $active; ?>>MANAGE</a></li> <li><a href="index.php?action=settings" <?php echo $active; ?>>SETTINGS</a></li> </ul> </div> Quote Link to comment Share on other sites More sharing options...
gevans Posted February 2, 2009 Share Posted February 2, 2009 Have you checked what value is assigned to $action? and if $active ever gets set? Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted February 2, 2009 Author Share Posted February 2, 2009 I took out the initial IF statement and replaced everything with this: <div class="navigation"> <ul> <li><a href="index.php?action=write" <?php if($action == 'write') { ?> class="active" <?php } ?>>WRITE</a></li> <li><a href="index.php?action=manage" <?php if($action == 'manage') { ?> class="active" <?php } ?>>MANAGE</a></li> <li><a href="index.php?action=settings" <?php if($action == 'settings') { ?> class="active" <?php } ?>>SETTINGS</a></li> </ul> </div> It works like a charm Quote Link to comment Share on other sites More sharing options...
trq Posted February 2, 2009 Share Posted February 2, 2009 Even better.... <div class="navigation"> <ul> <li><a href="index.php?action=write" <?php echo $action == 'write' ? 'class="active"' : ''; ?>>WRITE</a></li> <li><a href="index.php?action=manage" <?php echo $action == 'manage' ? 'class="active"' : ''; ?>>MANAGE</a></li> <li><a href="index.php?action=settings" <?php echo $action == 'settings' ? 'class="active"' : ''; ?>>SETTINGS</a></li> </ul> </div> Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted February 2, 2009 Author Share Posted February 2, 2009 hmmm i never understood the short hand of things... thus i shall keep the long way Quote Link to comment Share on other sites More sharing options...
trq Posted February 2, 2009 Share Posted February 2, 2009 Its not hard. expression ? true : false;[/i] If expression is true, return whats after the ? else return whats after the : Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted February 2, 2009 Author Share Posted February 2, 2009 hmmm i will have to study more into it.. thanks! The shorthand version just looks odd i reckon Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.