add a constant to a formula

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
podarum
Forum Commoner
Posts: 51
Joined: Mon Jun 15, 2009 1:36 pm

add a constant to a formula

Post by podarum »

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..

Code: Select all

 
<?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
iamngk
Forum Commoner
Posts: 50
Joined: Mon Jun 29, 2009 2:20 am

Re: add a constant to a formula

Post by iamngk »

Your $N is not placed in IF control structure more over it is placed in wrong place. Also for better handling of variable, you have to initiate the $N variable. Please try the below code.

Code: Select all

<?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'>
podarum
Forum Commoner
Posts: 51
Joined: Mon Jun 15, 2009 1:36 pm

Re: add a constant to a formula

Post by podarum »

You da man.... thanks... it worked perfectly...
podarum
Forum Commoner
Posts: 51
Joined: Mon Jun 15, 2009 1:36 pm

Re: add a constant to a formula

Post by podarum »

Ok, I'm back with more...

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 ?

Code: Select all

<?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'>
 
Post Reply