Jump to content

[SOLVED] php if not working


dennismonsewicz

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.