Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kgarner

macrumors 68000
Original poster
I am very new to PHP and just need to know if this code will work.

PHP:
<?php if ($thispage=="Rental Info" or "Rental Policy") echo "id=\"current\""; ?>

Tried looking at the manual online but I am still unclear. Would just try it, but I am away from my Mac.

Thanks.
 
How bout this instead

<?php if ($thispage=="Rental Info" || $thispage=="Rental Policy") echo "id=\"current\""; ?>
 
kingjr3 said:
How bout this instead

<?php if ($thispage=="Rental Info" || $thispage=="Rental Policy") echo "id=\"current\""; ?>

Thank you. That makes more sense to my limited training. I will give that a try.
 
to clarify: when the engine sees your original statement as written, it evaluates it as "if A or B is true, then..."

in this case, A is $thispage=="Rental Info", which is fine. but your B statement is just "Rental Policy". that isn't a conditional, so it's going to evaluate as true no matter what.

like kingjr3 said, the correct way to do it is to test both conditions with the equal operator, ==.
 
kingjr3 said:
How bout this instead

<?php if ($thispage=="Rental Info" || $thispage=="Rental Policy") echo "id=\"current\""; ?>

You can also try it this way:

PHP:
<?php echo ($thispage == "Rental Info" || $thispage == "Rental Policy")?"id=\"current\"":""; ?>

This is especially useful if you want to echo something if the condition isn't fulfilled:

PHP:
<?php echo ($thispage == "Rental Info" || $thispage == "Rental Policy")?"id=\"current\"":"id=\"not current\""; ?>

The code will echo "id=\"not current\"" if ($thispage != "Rental Info" && $thispage != "Rental Policy").
 
whocares said:
You can also try it this way:

(code sample)

This is especially useful if you want to echo something if the condition isn't fulfilled:

(code sample)

The code will echo "id=\"not current\"" if ($thispage != "Rental Info" && $thispage != "Rental Policy").

Thanks. I am using this to set the current status of a navigation pane. I am actually using multiple tests (eg if (blah) echo "blah" and then if (stuff) echo "stuff" and so on). I have the false setting after the whole list. I was looking for a way to have multiple pages set the same curent state (like subpages still showing you are in the Rental Info section). The suggestions worked great, by the way. Thanks for all the helpful advice.
 
kgarner said:
Thanks. I am using this to set the current status of a navigation pane. I am actually using multiple tests (eg if (blah) echo "blah" and then if (stuff) echo "stuff" and so on). I have the false setting after the whole list. I was looking for a way to have multiple pages set the same curent state (like subpages still showing you are in the Rental Info section). The suggestions worked great, by the way. Thanks for all the helpful advice.

Yeah, using boolean tests needs a minimum of 'logic'. 😛
It's always best to do a bit of thinking before coding and even draw a tree with the boolean tests. This helps when writing the code.
 
I just set up a site using this idea, the way I tackled having more than one page use the same tab is by setting up a section and page. So...

/index.php?section=home&page=main

or in your case

/index.php?section=rental&page=info
and
/index.php?section=rental&page=policy

This way as long as your in the rental section you get the rental tab. Also this allows for easy future expansion.
 
cool idea davecuse. I will look into that as this site is still a major work in progress.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.