Hi i need some help with an Else If statement. Basically I want to display some include text depending on where the user is i.e.
I want to pull in seo text for my homepages, using simple php includes, so index.php would pull in homepage_seo.php, aboutus.php would pull in aboutus_seo.php etc.
No i know that the statement has to be something like below, but I'm new to php, so any help would be great.
From W3 schools:
if (condition)
code to be executed if condition is true;
elseif (condition)
code to be executed if condition is true;
else
code to be executed if condition is false;
<?php
$d=date("D");
if ($d=="Fri")
echo "Have a nice weekend!";
elseif ($d=="Sun")
echo "Have a nice Sunday!";
else
echo "Have a nice day!";
?>
Thanks in advance,
Tony
Else if statements help -total newbie with a simple question
Moderator: General Moderators
-
mattpointblank
- Forum Contributor
- Posts: 304
- Joined: Tue Dec 23, 2008 6:29 am
Re: Else if statements help -total newbie with a simple question
(Try using the code tags to display your code like I'm doing here)
You're almost there, just missed the curly braces which indicate the start and end of the if statement:
You're almost there, just missed the curly braces which indicate the start and end of the if statement:
Code: Select all
<?php
$d=date("D");
if ($d=="Fri") {
echo "Have a nice weekend!";
} elseif ($d=="Sun") {
echo "Have a nice Sunday!";
} else {
echo "Have a nice day!";
}
?>
Re: Else if statements help -total newbie with a simple question
Hi,
that statement works fine, but how do i modify it to pull in my includes?
Tony
that statement works fine, but how do i modify it to pull in my includes?
Tony
Re: Else if statements help -total newbie with a simple question
UPDATE:
I have managed to locate the following code, which is doing the job, but the problem is that my default seo include is defaulting no matter what page i am on. The code i am using is below.
<?php
switch ($_SERVER['PHP_SELF']) {
case 'about-mb-centre-nottingham.php':
include 'seoaboutus.php';
break;
case 'mb-centre-contact-us.php':
include 'seocontact.php';
break;
case 'mb-centre-diagnostics.php':
include 'seodiagnostic.php';
break;
case 'mb-centre-faqs.php':
include 'seofaq.php';
break;
case 'mb-centre-mot.php':
include 'seomot.php';
break;
case 'mb-centre-ordering-parts.php':
include 'seoorderingparts.php';
break;
case 'mb-centre-repairs.php':
include 'seorepairs.php';
break;
case 'mb-centre-service.php':
include 'seoservices.php';
break;
case 'mb-centre-services.php':
include 'seombcservices.php';
break;
case 'mb-centre-used-cars.php':
include 'seousedcars.php';
break;
default:
include 'seohome.php';
break;
}
?>
I do have an alternative option:
if ($_SERVER['PHP_SELF'] == 'aboutus.php' {
include 'seoaboutus.php';
} else {
include 'seohome.php';
}
But the other one is better due to the multiple seo files.
Regards,
Tony
I have managed to locate the following code, which is doing the job, but the problem is that my default seo include is defaulting no matter what page i am on. The code i am using is below.
<?php
switch ($_SERVER['PHP_SELF']) {
case 'about-mb-centre-nottingham.php':
include 'seoaboutus.php';
break;
case 'mb-centre-contact-us.php':
include 'seocontact.php';
break;
case 'mb-centre-diagnostics.php':
include 'seodiagnostic.php';
break;
case 'mb-centre-faqs.php':
include 'seofaq.php';
break;
case 'mb-centre-mot.php':
include 'seomot.php';
break;
case 'mb-centre-ordering-parts.php':
include 'seoorderingparts.php';
break;
case 'mb-centre-repairs.php':
include 'seorepairs.php';
break;
case 'mb-centre-service.php':
include 'seoservices.php';
break;
case 'mb-centre-services.php':
include 'seombcservices.php';
break;
case 'mb-centre-used-cars.php':
include 'seousedcars.php';
break;
default:
include 'seohome.php';
break;
}
?>
I do have an alternative option:
if ($_SERVER['PHP_SELF'] == 'aboutus.php' {
include 'seoaboutus.php';
} else {
include 'seohome.php';
}
But the other one is better due to the multiple seo files.
Regards,
Tony