Forum Moderators: coopster

Message Too Old, No Replies

How do I do If/then conditional statements in PHP

         

123dhs321

6:25 pm on Dec 3, 2004 (gmt 0)

10+ Year Member



I want to do this statement in PHP. Here it is in ASP.

<% NavLocation="home" %>

<If NavLocation ="home" then %>class="foo"<% else %>class="foo1"<% end if %>

I cant find out for the life of me how to do this in PHP.

Thanks for helping...
-Ryan

CaseyRyan

6:33 pm on Dec 3, 2004 (gmt 0)

10+ Year Member



Here's the basic translation:

<?
$NavLocation='Home';
if ($NavLocation == 'Home') {
?> class='foo' <?
} else {
?> class='foo1' <?
}
?>

Here's a link to the page in documentation that covers this:
PHP Control Structures [us2.php.net]

-=casey=-

123dhs321

6:51 pm on Dec 3, 2004 (gmt 0)

10+ Year Member



How do I make the php specific per page?

This would be on top of home.asp
<% NavLocation="home" %>

This would be on top of inner1.asp
<% NavLocation="inner1" %>
-------------------------------------------

These are in my header include.....

<If NavLocation ="home" then %>class="foo"<% else %>class="foo1"<% end if %>

<If NavLocation ="inner1" then %>class="foo"<% else %>class="foo1"<% end if %>

I almost have it for php but I dont know how to specify which page to make the statment? I have this on top of my inner1 page :
<? $NavLocation='Inner1'?>

But, I dont want it on the home page...anyone have a clue what I'm talking about?

HughMungus

6:53 pm on Dec 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



123, a bit of advice to save you a lot of headache: php if/then statements us double = signs, e.g., if ($this == $that);

CaseyRyan

7:37 pm on Dec 3, 2004 (gmt 0)

10+ Year Member



I assume that this is for navigation. You're setting the class to highlight what page the user is currently on.

At the top of home page you will want:
<? $NavLocation = 'home';?>
At the top of the inner page you will want:
<? $NavLocation = 'Inner1';?>
and so on.

Your include will be after that variable is set.

If you do not want to have the tag at the top of the home page or if you want the home item to be highlighted by default, you should add the following bolded text to the If Statement for the home. It will catch instances where $NavLocation is not set or has been set to an empty string.

<?
if (($NavLocation == 'home') ¦¦ (empty($NavLocation)) ¦¦ (isset($NavLocation))){
?>class='foo'<?
}else{
?>class='foo1'<?
}
?>

-=casey=-

123dhs321

7:40 pm on Dec 3, 2004 (gmt 0)

10+ Year Member



ok..thanks for the help. I figured it out.

this is asp:
<% NavLocation="home" %> (goes with page home.asp)

<If NavLocation ="home" then %>class="foo"<% else %>class="foo1"<% end if %>

-----------------------------------------
this is the exact same thing in php:

<? $NavLocation='Home'; if ($NavLocation == 'Home')?> (goes with page home.php)

<? if ($NavLocation == 'Home') {?>class="foo"<? } else {?>class="foo1"<? }?>

I really think asp is an easier language to understand and write, but thats my bias opinion. I'm used to it.

-ryan

123dhs321

7:45 pm on Dec 3, 2004 (gmt 0)

10+ Year Member



oops! I just saw your post casey. Thanks for the help and understanding. I will be using YOUR code, I pieced my together from what people said on this thread. You're correct about me making sticky navigation. Thanks for showing me this. It's a very valuable tool for me.

-ryan