/    Sign up×
Community /Pin to ProfileBookmark

PHP If statements….

Hi, I am wondering what I’m doing wrong.

I am using conditional IF statements to display specific text on a dynamic thank you page. Depending on the list a person is subscribed to, the text on the than you page will vary. However, certain text is the same across all lists. For instances where the text should be the same regardless of the list, I would like a simple IF statement, instead of having to keep using ‘elseif’ over and over again.

Here is what I have tried:

[code=php] <?php

if ($list_name==”list1″)
{
$list_name==”list2″;
$list_name==”list3″;
$list_name==”list4″;
$list_name==”list5″;
echo “So act now.”;
}
else
echo “”;
?>[/code]

However, nothing happens. Where the text “So act now.” should be, it is blank.

Thanks in advance for any help with this.

~minnie

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogAug 07.2012 — If I'm understanding the question correctly, you might find something like this useful:
[code=php]
if(in_array($list_name, array('list1', 'list2', 'list3', 'list4', 'list5')) {
echo "So act now.";
}
[/code]


If you want to do it with an typical if(), then you would need to use the logical "or" operator (either "or" or "||"):
[code=php]
if(
$list_name == 'list1' or
$list_name == 'list2' or
$list_name == 'list3' or
$list_name == 'list4' or
$list_name == 'list5'
) {
echo "So act now.";
}
[/code]

Charles's suggestion can clean that up a bit as:
[code=php]
switch($list_name) {
case 'list1':
case 'list2':
case 'list3':
case 'list4':
case 'list5':
echo "So act now.";
break;
default:
echo ""; // not really necessary since you're not really doing anything
// but shows how you would do an else-like effect with switch()
}
[/code]
Copy linkTweet thisAlerts:
@minnieminnieauthorAug 07.2012 — Thank you Charles and NogDog. I've input the switch statement and it works as intended!

~Minnie
×

Success!

Help @minnieminnie spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...