PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
michlcamp
Forum Commoner
Posts: 78 Joined: Mon Jul 18, 2005 11:06 pm
Post
by michlcamp » Sat Mar 03, 2007 11:22 pm
Is there a way to use IF statements with includes?
I want to put specific include files on specific pages -
something like
Code: Select all
IF (thispageurl = http://mydomain.com/aboutme.php)
{include("aboutme_menu.php")}
ELSEIF (thispageurl = http://mydomain.com/contactme.php)
{include("contactme_menu.php")}
,etc...
know what I want to do but don't know how to write it..
thanks in advance...
mc
dibyendrah
Forum Contributor
Posts: 491 Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:
Post
by dibyendrah » Sun Mar 04, 2007 12:48 am
Correction to your code to work with PHP.
Code: Select all
<?php
if($thispageurl = "http://mydomain.com/aboutme.php"){
include("aboutme_menu.php");
}elseif ($thispageurl = "http://mydomain.com/contactme.php"){
include("contactme_menu.php");
}
?>
See control structure of php manual for more information
http://php.net/manual/en/language.contr ... ctures.php
jmut
Forum Regular
Posts: 945 Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:
Post
by jmut » Sun Mar 04, 2007 12:55 am
sure it is possible but seems you should read little about php first. Variables, control structures etc.
Code: Select all
if ($variable == 'someString') {
include('script1.php');
}elseif ($variable == 'someString2') {
include('script2.php');
}
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Mar 04, 2007 9:05 am
There's a thread linked from Useful Posts that may be of interest regarding includes.
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Mon Mar 05, 2007 3:33 pm
And make sure when checking equality that you use == (or === for type and value equality), not a single =, as this is assignment, not equality.
This one has bit me on more than one occassion I'm afraid, so I tell as many people as I can to watch for it.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Mon Mar 05, 2007 4:52 pm
That's why it's a good idea to write the literal on the left side.
Code: Select all
<?php
if ( 'xyz'=$var ) { // syntax error
// ...
}
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Mon Mar 05, 2007 4:56 pm
Good advice volka. I probably should have mentioned that as well
.