View Full Version : Easy PHP question
kgarner
Mar 25, 2004, 03:39 PM
I am very new to PHP and just need to know if this code will work.
<?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.
jeremy.king
Mar 25, 2004, 03:43 PM
How bout this instead
<?php if ($thispage=="Rental Info" || $thispage=="Rental Policy") echo "id=\"current\""; ?>
kgarner
Mar 25, 2004, 03:48 PM
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.
sonofslim
Mar 25, 2004, 03:58 PM
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, ==.
whocares
Mar 25, 2004, 06:50 PM
How bout this instead
<?php if ($thispage=="Rental Info" || $thispage=="Rental Policy") echo "id=\"current\""; ?>
You can also try it this way:
<?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 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").
kgarner
Mar 26, 2004, 10:38 AM
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.
davecuse
Mar 26, 2004, 11:11 AM
If you're looking for ideas on how to use PHP to determine what your navigation should show, you might want to check out this article
Keeping Navigation Current With PHP (http://alistapart.com/articles/keepingcurrent/)
whocares
Mar 26, 2004, 11:23 AM
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'. :p
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.
kgarner
Mar 26, 2004, 12:49 PM
If you're looking for ideas on how to use PHP to determine what your navigation should show, you might want to check out this article
Keeping Navigation Current With PHP (http://alistapart.com/articles/keepingcurrent/)
That is actually what I was using as a guide. :) I just needed a little input on having multiple pages refer to the same tab.
davecuse
Mar 26, 2004, 01:06 PM
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.
kgarner
Mar 26, 2004, 01:16 PM
cool idea davecuse. I will look into that as this site is still a major work in progress.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.