Results 1 to 3 of 3

Thread: If and include

  1. #1
    Join Date
    Nov 2005
    Location
    Austin TX,US
    Posts
    71
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default If and include

    I want to have different left nav for differernt areas of the site, for example if the pages are about company, I use the following,... but it doesn't work:

    Code:
    <?php 
      if($navL.indexOf("company")!==-1) include($_SERVER['DOCUMENT_ROOT'].'/site/navL_company.php'); ?>
    At the beginning of each page in the Company area, I put:
    $navL="company_about"
    or $navL="company_locations"....

    What's wrong? Thanks!

  2. #2
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    Eh, there's easier ways to do this. For example, add this onto the url: ?company=yes.

    Then:

    PHP Code:
    if(@$_GET['company']){
        
    $co $_GET['company'];
        if(
    $co == 'yes'){
            include(
    'site/navL_company.php');}
        else if(
    $co == 'no'){
            include(
    'site/navL.php');}
        else{include(
    'site/navL.php');}}
    else{include(
    'site/navL.php');} 
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  3. #3
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    It is because PHP does not have a built-in function called indexOf (that's in Javascript). Anyways, you could try using strstr to find out if the word "company" has been passed like so:

    Code:
    <?php 
    if(strstr($navL, 'company')) { 
    include($_SERVER['DOCUMENT_ROOT'].'/site/navL_company.php'); 
    }
    ?>
    Hope this helps.

    //EDIT: sorry alex, cross posted.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •