Jump to content


Photo

If statements in middle of text block


  • Please log in to reply
4 replies to this topic

#1 dark dude

dark dude
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 22 October 2006 - 04:21 PM

I'm having some problems with this:

$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!
.}';

It doesnt seem to want the if statements there to work :(

Any help?


Thanks,
~Dark dude~

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 22 October 2006 - 05:02 PM

such a messy piece of 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!';}

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 22 October 2006 - 05:04 PM

Try this version:

$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 it
if($DefHaloMoonFig2=='0') { 
    $DefBody.= ' The Attacker has won the battle!';
} else {
    $DefBody.= 'The Defender has won the battle!';
}

Legend has it that reading the manual never killed anyone.
My site

#4 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 22 October 2006 - 05:34 PM

Use the ternary operator within variable or flush type assignments!

<?php

$a = 1;

echo 'the ' . ( $a == 1 ? 'sky' : 'water' ) . ' was blue';

?>

me!

#5 dark dude

dark dude
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 22 October 2006 - 06:30 PM

Thanks AndyB and Crayon Violet, that worked perfectly. I see why you guys are Global Mods ^^




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users