podarum Posted September 30, 2009 Share Posted September 30, 2009 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 More sharing options...
Ingolme Posted September 30, 2009 Share Posted September 30, 2009 What's your definition of "field"? Link to comment Share on other sites More sharing options...
Synook Posted September 30, 2009 Share Posted September 30, 2009 And "constant"? Link to comment Share on other sites More sharing options...
podarum Posted September 30, 2009 Author Share Posted September 30, 2009 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 More sharing options...
Ingolme Posted September 30, 2009 Share Posted September 30, 2009 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 More sharing options...
podarum Posted September 30, 2009 Author Share Posted September 30, 2009 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) Link to comment Share on other sites More sharing options...
Ingolme Posted September 30, 2009 Share Posted September 30, 2009 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 More sharing options...
podarum Posted September 30, 2009 Author Share Posted September 30, 2009 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 More sharing options...
justsomeguy Posted September 30, 2009 Share Posted September 30, 2009 You can either use $N=$N+1 or $N++ to increment $N. Link to comment Share on other sites More sharing options...
podarum Posted September 30, 2009 Author Share Posted September 30, 2009 See, I tried $N=$N+1 and that diodn't work.. all I get is 2 even if there are like 4 or 5 $N's populated with 1 Link to comment Share on other sites More sharing options...
justsomeguy Posted September 30, 2009 Share Posted September 30, 2009 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 More sharing options...
Synook Posted October 1, 2009 Share Posted October 1, 2009 Note - PHP considers null-values (e.g. 0 and "") false. Link to comment Share on other sites More sharing options...
Ingolme Posted October 1, 2009 Share Posted October 1, 2009 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.