Jump to content

multiple if statements and an else... displaying else.


87dave87

Recommended Posts

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]
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.