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~ 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] 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] 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! 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 ^^ 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
Archived
This topic is now archived and is closed to further replies.