Clinton Posted June 4, 2008 Share Posted June 4, 2008 This is the original code: $kuccpitexpire = strtotime($kuccpit.'+ 12 months'); $kuccpitexpire = date('n/j/Y',$kuccpitexpire); $kuccpit = strtotime($kuccpit.'+ 11 months'); $kuccpit = date('Y-m-d',$kuccpit); if ($nowtrue > $kuccpit) { echo " $fname $lname is due for the KUCC Hazard Recognition Precious Metals Program! It Expires $kuccpitexpire "; } Now, I am trying to add an If statement to the begining of it, a couple of different ways, and I can't figure it out. This is what I have currently: if ($row{'kuccpit'}=='0000-00-00') echo " "; else $kuccpitexpire = strtotime($kuccpit.'+ 12 months'); $kuccpitexpire = date('n/j/Y',$kuccpitexpire); $kuccpit = strtotime($kuccpit.'+ 11 months'); $kuccpit = date('Y-m-d',$kuccpit); ($nowtrue > $kuccpit) { echo "<center> $fname $lname is due for the KUCC Pit License! It Expires $kuccpitexpire <p></center>"; } Quote Link to comment https://forums.phpfreaks.com/topic/108743-solved-elseif-help/ Share on other sites More sharing options...
runnerjp Posted June 4, 2008 Share Posted June 4, 2008 i think this should work ... not tested <?php if ($row{'kuccpit'}=='0000-00-00'){ echo " ";} else { $kuccpitexpire = strtotime($kuccpit.'+ 12 months'); $kuccpitexpire = date('n/j/Y',$kuccpitexpire); $kuccpit = strtotime($kuccpit.'+ 11 months'); $kuccpit = date('Y-m-d',$kuccpit); if ($nowtrue > $kuccpit) { echo " $fname $lname is due for the KUCC Hazard Recognition Precious Metals Program! It Expires $kuccpitexpire "; }} ?> Quote Link to comment https://forums.phpfreaks.com/topic/108743-solved-elseif-help/#findComment-557654 Share on other sites More sharing options...
discomatt Posted June 4, 2008 Share Posted June 4, 2008 The only time you don't need to use curly braces on conditional statements if when there's only 1 evaluation/function to be performed within that condition. Examples below <?php $bool = FALSE; if ( $bool = TRUE ) echo 'This will work fine, but will not be outputted'; else echo 'This will work fine, and will be outputted'; if ( $bool = FALSE ) echo 'This will work fine, and will be outputted'; else echo 'This will work fine, but will not be outputted'; echo 'This will work fine, and will be outputted, because the else statement ended after the above echo'; if ( $bool = TRUE ) echo 'This will work fine, but will not be outputted'; echo 'This will break ths script, because the if statement ended after the above echo, so the else below will not have a corresponding if statment'; else echo 'This would work, but the above broke the script'; if ( $bool = TRUE ) { echo 'This will work fine, but will not be outputted'; echo 'This will also work fine because it is within the if\'s curley brace'; } else echo 'This will work fine, and will be outputted'; # Alternately if ( $bool = TRUE ) echo 'This will work fine, and will be outputted'; else { echo 'This will work fine, but will not be outputted'; echo 'This will also work fine because it is within the if\'s curley brace'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/108743-solved-elseif-help/#findComment-557684 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.