Conditional statement not working

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve Fitzgerald

    Conditional statement not working

    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');
    }
    ?>
  • Jon Kraft

    #2
    Re: Conditional statement not working

    Steve Fitzgerald <sf@mnetsys.com > wrote:
    [color=blue]
    > 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']){[/color]

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

    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

    Comment

    • Steve Fitzgerald

      #3
      Re: Conditional statement not working

      It worked! Thanks.

      Jon Kraft <jon@jonux.co.u k> wrote in message news:<bmopdm$pj 9dp$1@ID-175424.news.uni-berlin.de>...[color=blue]
      > Steve Fitzgerald <sf@mnetsys.com > wrote:
      >[color=green]
      > > 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']){[/color]
      >
      > $p is actually empty here. If $_GET['home'] is also empty the above
      > statement would be true.
      >[color=green]
      > > include ('pages/home.php');
      > > } elseif (@$p != $_GET['home']){[/color]
      >
      > 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[/color]

      Comment

      Working...