Jump to content

Adding A Constant To A Formula


podarum

Recommended Posts

I'm trying to create a new field call it $N, and I want to give it a value of 1 where ever there is an image in the formual..take a look..

<?php if(($OpenDT=="") or ($CurrentDT=="")) {echo "";} elseif($Months<=6) {echo '<img src="images/check.png" width="25" height="20">';} $N=1 elseif($Months<=12) {echo "";} else {echo "";}?><TD align=center bordercolor='#f6faff'>

So when $Months <=6, I want the image plus the field $N to equal =1 .. any idea .. thanks

Link to comment
Share on other sites

Thanks guys, but I got the answer..maybe I made it sound harder than it actually is...

<?php $N=0; if(($OpenDT=="") or ($CurrentDT=="")) {echo "";} elseif($Months<=6) {echo '<img src="images/check.png" width="25" height="20">'; $N=1; } elseif($Months<=12) {echo "";} else {echo "";}?><TD align=center bordercolor='#f6faff'>

Link to comment
Share on other sites

you have a lot of pointless code there. Your elseif, else and echo ""; statements do nothing at all.You could simplify it to this:

<?php  $N = 0;  if($OpenDT && $CurrentDT && $Months<=6) {	$N = 1;	echo '<img src="images/check.png" width="25" height="20">';  }?>

Link to comment
Share on other sites

your code has nothing to do with what I want to achieve, you're inserting an image even if $OpenDT=="", and that's not what I want... I only want the image and the $N=1 to only when ($Months<=6)
All I did was to simplify the expression you had there already.And it will not show an image if $OpenDT is an empty string. An empty string evaluates to false in an expression.
Link to comment
Share on other sites

I see...Any idea how I can count in php.. for example, Now that I have $N=1, for everytime the $N gets a 1 (see the second <?php ($Age<=6) also assigns the $N another 1 for a total of 2 now and so forth... How can I count them ? so now I have a new field say $N2 that counts all the $N's

<?php $N=0; if(($OpenDT=="") or ($CurrentDT=="")) {echo "";} elseif($Months<=6) {echo '<img src="images/check.png" width="25" height="20">'; $N=1; } elseif($Months<=12) {echo "";} else {echo "";}?><TD align=center bordercolor='#f6faff'> <?php $N=0; if(($OpenDT=="") or ($CurrentDT=="")) {echo "";} elseif($Age<=6) {echo '<img src="images/check.png" width="25" height="20">'; $N=1; } elseif($Age<=12) {echo "";} else {echo "";}?><TD align=center bordercolor='#f6faff'>

Link to comment
Share on other sites

Do you keep resetting $N to 0 every time? You should be using a running counter here, not resetting it every time. There isn't more than one $N, $N is a single variable with a single value. If you want to use it as a counter then continue to increment it without resetting it each time.

Link to comment
Share on other sites

You should indent your code, then you could see what's going on better:

<?php  $N=0;	if( ($OpenDT=="") or ($CurrentDT=="") ) {		$echo "";	} elseif($Months<=6) {		echo '<img src="images/check.png" width="25" height="20">';		$N=1;	} elseif ($Months<=12) {		echo "";	} else {		echo "";	}?><TD align=center bordercolor='#f6faff'><?php	$N=0;	if( ($OpenDT=="") or ($CurrentDT=="") ) {		echo "";	} elseif ($Age<=6) {		echo '<img src="images/check.png" width="25" height="20">';		$N=1;	} elseif ($Age<=12) {		echo "";	} else {		echo "";	}?><TD align=center bordercolor='#f6faff'>

Do you notice that all thise echo ""; lines are pointless?And these two expressions can be simplified: if( ($OpenDT=="") or ($CurrentDT=="") ) elseif ( $Age<=6 )By using elseif, all you're doing is applying a logical not to the other expression, which means you can simplify it to this:

  if(	!( ($OpenDT=="") or ($CurrentDT=="") )	&&	$Age <= 6  )

It can be further simplified, using de Morgan's laws, into this:

  if(	$OpenDT  or $CurrentDT	&&	$Age <= 6  )

Finally, based off pure logic, you can completely get rid of this part, because it does virtually nothing at all

  elseif ($Age<=12) {		echo "";	} else {		echo "";	}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...