SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Nov 2001
    Location
    Fort Lauderdale
    Posts
    814
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Run elseif statement depdending on the URL

    Currently in my website the "Title" is dynamically created in php using several variables from my Mysql database.

    The problem I'm having is that depending on the particular section of the website i'm on, I would like to slightly adjust the title formating.

    Here is what I was testing with the following code:

    Code:
    <?
    $urlcustom = $_SERVER['SERVER_NAME'];
    $pagecustom = $_SERVER['REQUEST_URI'];
    $webpagecustom = "http://".$urlcustom.$pagecustom;
    if($webpagecustom == "http://www.mydomain.com/")
    echo "Welcome to mydomain.com";
    elseif ($webpagecustom == "http://www.mydomain.com/sitesearch/$searchid/$searchlink")
    echo "Search results from Mydomain.com";
    elseif ($webpagecustom == "http://www.mydomain.com/sitesection/$browsecat/$ppage/$category")
    echo "Browsing $category on Mydomain.com";
    else
    echo "$pagetitle  on Mydomain.com";
    ?>
    So far here is what happens:
    1. When on mydomain.com it displays the correct text from the IF statement.

    2. When on mydomain.com/anythingelse it only displays the last Else statement.

    3. Basically the IF statement works and the ELSE statement works but none of the ELSEIF statements work.

    I can't exactly see the reason why it only outputs the last else statement instead of displaying the correct one. I'm not exactly sure how to change the elseif statement so that it works correctly.

    I'm guessing it's because of the URL's being generated from php, but I've been googling for hours and not exactly sure if i'm even on the right path lol.

    Any advice and feed would be greatly appreciated.

    Thank you in advance.

  2. #2
    SitePoint Zealot
    Join Date
    May 2006
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would consider using switch


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
  •