87dave87 Posted November 21, 2006 Share Posted November 21, 2006 What am I doing wrong with this code? When the if statement is used it still displays the else <title> too.[code]<? $url = $_SERVER['REQUEST_URI']; if($url == '/') { echo "<title>emulators.cc - "; echo $num_rows; echo " console and handheld emulators for Windows, Mac and Linux computers"; echo "</title>"; }if(strpos($url, "about")!== false) { echo "<title>emulators.cc > About Us</title>"; }if(strpos($url, "search")!== false) { echo "<title>emulators.cc > Search results for "; echo $_POST['emusearch']; echo " ("; echo $num_rows; echo ")"; echo "</title>"; }if(strpos($url, "windows")!== false) { echo "<title>emulators.cc > Windows Emulators > "; echo $platform['platform']; echo " ("; echo $num_rows; echo ")"; echo "</title>"; }if(strpos($url, "mac")!== false) { echo "<title>emulators.cc > Mac Emulators > "; echo $platform['platform']; echo " ("; echo $num_rows; echo ")"; echo "</title>"; }if(strpos($url, "linux")!== false) { echo "<title>emulators.cc > Linux Emulators > "; echo $platform['platform']; echo " ("; echo $num_rows; echo ")"; echo "</title>"; }else { echo "<title>emulators.cc - console and handheld emulators for Windows, Mac and Linux computers</title>"; }?> [/code] Quote Link to comment Share on other sites More sharing options...
trq Posted November 21, 2006 Share Posted November 21, 2006 You shoul be using if elseif else. With a series of elseifs. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 21, 2006 Share Posted November 21, 2006 As you have it, the "else" clause only pertains to the last "if", so it will always be invoked unless the word "linux" is in the variable "$url".What you need to do is change all "if" statements, except the first to "elseif" statements, then it should work as you expect.Ken Quote Link to comment Share on other sites More sharing options...
87dave87 Posted November 21, 2006 Author Share Posted November 21, 2006 thanks! Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted November 21, 2006 Share Posted November 21, 2006 perhaps you might be better using the switch - it will be mreo efficient.[code]switch (true){ case preg_match('/about/', $url): break; case preg_match('/search/', $url): break; ... ad nausea ...}[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.