dark dude Posted October 22, 2006 Share Posted October 22, 2006 I'm having some problems with this:[code]$DefBody = '[Some irrelevant code/]<tr><td>Halo Moons</td><td>'.$PresetDefHaloMoonFig.'</td><td>'.$DefHaloMoonFig2.'</td></tr></table>'.if($DefHaloMoonFig2=='0'){.' The Attacker has won the battle!'. } else {.'The Defender has won the battle!.}';[/code]It doesnt seem to want the if statements there to work :(Any help?Thanks,~Dark dude~ Quote Link to comment https://forums.phpfreaks.com/topic/24749-if-statements-in-middle-of-text-block/ Share on other sites More sharing options...
.josh Posted October 22, 2006 Share Posted October 22, 2006 such a messy piece of code...[code]$DefBody = '[Some irrelevant code/]<tr><td>Halo Moons</td><td>'.$PresetDefHaloMoonFig.'</td><td>'.$DefHaloMoonFig2.'</td></tr></table>';if($DefHaloMoonFig2=='0'){$DefBody.=' The Attacker has won the battle!'; } else {$DefBody.='The Defender has won the battle!';}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/24749-if-statements-in-middle-of-text-block/#findComment-112702 Share on other sites More sharing options...
AndyB Posted October 22, 2006 Share Posted October 22, 2006 Try this version:[code]$DefBody = '[Some irrelevant code/]<tr><td>Halo Moons</td><td>'.$PresetDefHaloMoonFig.'</td><td>'.$DefHaloMoonFig2.'</td></tr></table>'; // end of first part of definition// now define the conditional adder and concatentate itif($DefHaloMoonFig2=='0') { $DefBody.= ' The Attacker has won the battle!';} else { $DefBody.= 'The Defender has won the battle!';}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/24749-if-statements-in-middle-of-text-block/#findComment-112704 Share on other sites More sharing options...
printf Posted October 22, 2006 Share Posted October 22, 2006 Use the [b]ternary[/b] operator within variable or flush type assignments![code]<?php$a = 1;echo 'the ' . ( $a == 1 ? 'sky' : 'water' ) . ' was blue';?>[/code]me! Quote Link to comment https://forums.phpfreaks.com/topic/24749-if-statements-in-middle-of-text-block/#findComment-112717 Share on other sites More sharing options...
dark dude Posted October 22, 2006 Author Share Posted October 22, 2006 Thanks AndyB and Crayon Violet, that worked perfectly. I see why you guys are Global Mods ^^ Quote Link to comment https://forums.phpfreaks.com/topic/24749-if-statements-in-middle-of-text-block/#findComment-112734 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.