SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Nov 2001
    Fort Lauderdale
    0 Post(s)
    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:

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

    2. When on 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
    0 Post(s)
    0 Thread(s)
    I would consider using switch


Posting Permissions

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