Novice@PHP Posted January 23, 2011 Share Posted January 23, 2011 I have this code which checks for the word "Big Ben" and if it's not there it outputs some html. I want t be able to make another statement to also check for the word "London Tower" and if it's not there then to check for the word "Canary Wharf", So far I've only managed one statement without the code breaking, how do I add the others in as well. <?php $astacker=get_post_meta($post->ID, 'thesite', true); if ( $astacker == [b]'Big Ben'[/b]) { ?> <?php include(TEMPLATEPATH."/feedsgrabstack.php");?> <?php }else { ?> <div id="splitter"><div class="clear"> <a href="<?php echo get_post_meta($post->ID, "linktosource", true);?>">Click Here To View Answers</a> <span style="float:right;"><a href="#related">See Related Questions</a></div></div> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/225443-repeat-statement-with-elseif/ Share on other sites More sharing options...
requinix Posted January 24, 2011 Share Posted January 24, 2011 Use an else if. Quote Link to comment https://forums.phpfreaks.com/topic/225443-repeat-statement-with-elseif/#findComment-1164174 Share on other sites More sharing options...
Novice@PHP Posted January 24, 2011 Author Share Posted January 24, 2011 Can anyone elaborate on the guy aboves answer and show an example of elseif using the code above without echoing? Quote Link to comment https://forums.phpfreaks.com/topic/225443-repeat-statement-with-elseif/#findComment-1164729 Share on other sites More sharing options...
BlueSkyIS Posted January 24, 2011 Share Posted January 24, 2011 an example <?php $astacker=get_post_meta($post->ID, 'thesite', true); if ( $astacker == [b]'Big Ben'[/b]) { include(TEMPLATEPATH."/feedsgrabstack.php"); } else if ( $astacker == [b]'London Tower'[/b] { // Do something else.. } else { ?> <div id="splitter"><div class="clear"> <a href="<?php echo get_post_meta($post->ID, "linktosource", true);?>">Click Here To View Answers</a> <span style="float:right;"><a href="#related">See Related Questions</a></div></div> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/225443-repeat-statement-with-elseif/#findComment-1164731 Share on other sites More sharing options...
AbraCadaver Posted January 24, 2011 Share Posted January 24, 2011 If you want to do the same thing if the variable is any of those, then something like this: $landmarks = array('Big Ben', 'London Tower', 'Canary Wharf'); if(in_array($astacker, $landmarks)) { include(TEMPLATEPATH."/feedsgrabstack.php"); // do something if any of the three match } else { // do default thing } Might be easier with a switch if you want to do something different depending on the value of the variable: switch($astacker) { case 'Big Ben': include(TEMPLATEPATH."/feedsgrabstack.php"); break; case 'London Tower': // do something break; case 'Canary Wharf': // do something break; default: // do default thing break; } Quote Link to comment https://forums.phpfreaks.com/topic/225443-repeat-statement-with-elseif/#findComment-1164743 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.