Jump to content

[SOLVED] Else/If Help


Clinton

Recommended Posts

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>";
}

Link to comment
https://forums.phpfreaks.com/topic/108743-solved-elseif-help/
Share on other sites

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
";
}} ?>

Link to comment
https://forums.phpfreaks.com/topic/108743-solved-elseif-help/#findComment-557654
Share on other sites

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';
}

?>

Link to comment
https://forums.phpfreaks.com/topic/108743-solved-elseif-help/#findComment-557684
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.