URGENT.. I Need Help Solving A Simple Sidebar elseif Problem

Discussion in 'PHP' started by Fat_Man, Nov 20, 2010.

  1. #1
    Okay This Might Be a Very Easy Question. I have about 10 pages and I would like them to all display a different set of links (links that are relevant to the page).

    Unfortunately the pages are created dynamically and they are not static nor can they be.

    What I would like to do is something like this:

    if (url == htttp://www.examplesite.com/page1/)

    {
    echo <a href=blahblahblah.html>blahblahblah</a>
    }

    elseif (url == htttp://www.examplesite.com/page2/)

    {
    echo <a href=blahblahblah.html>blahblahblah</a>
    }

    etc.etc.etc.

    Now the only problem I am having is the part with the URL. I know URL needs to be declared as a variable of some sort (god I hope I am saying this right) but I dont know what that variable is.

    Can someone please break it down to me in laymans terms. Maybe even write me out an example because I looked over some other sites and was completely confused by the code.

    I would really appreciate the help. Thank you in advance
     
    Fat_Man, Nov 20, 2010 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    Maybe this ?

    
    <?php
    
    if ($_SERVER['SCRIPT_NAME'] == '/page1') {
      echo '<a href="blahblahblah.html">blahblahblah</a>';
    }elseif{
     ($_SERVER['SCRIPT_NAME'] == '/page2')
      echo '<a href="blahblahblah.html">blahblahblah</a>';
    }elseif{
     ($_SERVER['SCRIPT_NAME'] == '/page3')
      echo '<a href="blahblahblah.html">blahblahblah</a>';
    }
    ?>
    
    PHP:
     
    MyVodaFone, Nov 20, 2010 IP