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> Link to comment https://forums.phpfreaks.com/topic/143508-solved-php-if-not-working/ 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? Link to comment https://forums.phpfreaks.com/topic/143508-solved-php-if-not-working/#findComment-752826 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 Link to comment https://forums.phpfreaks.com/topic/143508-solved-php-if-not-working/#findComment-752829 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> Link to comment https://forums.phpfreaks.com/topic/143508-solved-php-if-not-working/#findComment-752838 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 Link to comment https://forums.phpfreaks.com/topic/143508-solved-php-if-not-working/#findComment-752842 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 : Link to comment https://forums.phpfreaks.com/topic/143508-solved-php-if-not-working/#findComment-752846 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 Link to comment https://forums.phpfreaks.com/topic/143508-solved-php-if-not-working/#findComment-752858 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.