By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,053 Members | 1,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,053 IT Pros & Developers. It's quick & easy.

Conditional statement not working

P: n/a
This should be so easy, but it is not working.

What should happen is that if $p=home in the url then it displays
home.php and if $p does not equal home then it displays page.php which
is a template.

What am I missing?
<?php
// display page

if (@$p == $_GET['home']){
include ('pages/home.php');
} elseif (@$p != $_GET['home']){
include ('pages/page.php');
}else{
include ('pages/home.php');
}
?>
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Steve Fitzgerald <sf@mnetsys.com> wrote:
This should be so easy, but it is not working.

What should happen is that if $p=home in the url then it displays
home.php and if $p does not equal home then it displays page.php which
is a template.

What am I missing?

<?php
// display page

if (@$p == $_GET['home']){
$p is actually empty here. If $_GET['home'] is also empty the above
statement would be true.
include ('pages/home.php');
} elseif (@$p != $_GET['home']){


As $p is always empty, the above would be true if $_GET['home'] is not
empty.

If I understood you correctly, you have a parameter called 'p' in your URL
which sometimes is set to "home", sometimes not.

So you would check:

if (isset($_GET['p']) && $_GET['p']=="home"){
include ('pages/home.php');
} elseif (isset($_GET['p']) && $_GET['p']!="home"){
include ('pages/page.php');
}else{
include ('pages/home.php');
}

HTH;
JOn
Jul 17 '05 #2

P: n/a
It worked! Thanks.

Jon Kraft <jo*@jonux.co.uk> wrote in message news:<bm************@ID-175424.news.uni-berlin.de>...
Steve Fitzgerald <sf@mnetsys.com> wrote:
This should be so easy, but it is not working.

What should happen is that if $p=home in the url then it displays
home.php and if $p does not equal home then it displays page.php which
is a template.

What am I missing?

<?php
// display page

if (@$p == $_GET['home']){


$p is actually empty here. If $_GET['home'] is also empty the above
statement would be true.
include ('pages/home.php');
} elseif (@$p != $_GET['home']){


As $p is always empty, the above would be true if $_GET['home'] is not
empty.

If I understood you correctly, you have a parameter called 'p' in your URL
which sometimes is set to "home", sometimes not.

So you would check:

if (isset($_GET['p']) && $_GET['p']=="home"){
include ('pages/home.php');
} elseif (isset($_GET['p']) && $_GET['p']!="home"){
include ('pages/page.php');
}else{
include ('pages/home.php');
}

HTH;
JOn

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.